首页 > 代码库 > 在PythonAnyWhere上部署Django项目

在PythonAnyWhere上部署Django项目

http://www.jianshu.com/p/91047e3a4ee9

将项目放到git上,然后将pathonanywhere上的ssh传到git上,没有的话先创建,然后从git上把项目拷贝到pathonanywhere的根目录下/home/xqnq2007下

1 创建虚拟环境,

mkvirtualenv rango
将各种包安装在虚拟环境中,这样会避免出现某些权限不足的问题


2

配置Virtualenv

将对应的文件路径写正确

创建web app成功后,在Web标签页面会出现你创建的web app相关配置信息,我称之为项目管理页面。在该页面找到Virtualenv,点击Enter a path to a virtualenv, if desired,替换成你自己的virtualenv路径,如:/home/<username>/.virtualenvs/rango

配置WSGI代码

在项目管理页面找到WSGI configuration file: [/var/www/<username>_pythonanywhere_com_wsgi.py],点击该py文件,只保留以下代码,其余代码删除(或注释掉):

# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at ‘/home/<username>/mysite/mysite/settings.py‘
## and your manage.py is is at ‘/home/<username>/mysite/manage.py‘
path = ‘/home/<username>/tango_with_django‘
if path not in sys.path:
    sys.path.append(path)
#
os.environ[‘DJANGO_SETTINGS_MODULE‘] = ‘tango_with_django_project.settings‘
#
## then, for django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
## or, for older django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

4 配置静态文件
在项目管理页面找到Static files,点击Enter URL,输入/static/admin,点击对应的Enter path,输入/home/<username>/.virtualenvs/rango/lib/python2.7/site-packages/django/contrib/admin/static/admin,以上步骤添加了admin相关页面的静态文件;下面添加应用中的静态文件,再次点击Enter URL,输入/static/,点击对应的Enter path,输入/home/<username>/tango_with_django/static/
此处tango with django的教程还有个坑,它对应的/static/path/home/<username>/tango_with_django/tango_with_django_project/static,路径中多了一个tango_with_django_project
5 导入数据库,在bash 通过命令行导入
调试技巧,看error log
http://blog.csdn.net/zhu_free/article/details/46279725
https://my.oschina.net/hding/blog/615243
https://segmentfault.com/a/1190000009240824
https://www.v2ex.com/t/195207
http://www.cnblogs.com/kuihua/p/5577276.html
http://www.cnblogs.com/llw1121/p/6957039.html

在PythonAnyWhere上部署Django项目