我在本地创建了一个Django应用程序,我想在PythonAnywhere.com上托管它。我按照https://help.pythonanywhere.com/pages/VirtualEnvForNewerDjango上的说明进行操作,并创建了一个安装了1.9的virtualenv
。但是,当我尝试运行我的应用时,收到错误ImportError: No module named myapp.settings
这是我的username_pythonanywhere_com_wsgi.py
import os
import sys
# add your project directory to the sys.path
project_home = u'/home/rhpt'
if project_home not in sys.path:
sys.path.append(project_home)
# set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
# serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我也试过myapp.my_app.settings
但没有成功。
我的树
myapp
├── my_app
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── get_data
│ ├── __init__.py
│ ├── admin.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── manage.py
答案 0 :(得分:6)
如果您的settings.py
文件位于/home/rhpt/myapp/my_app/settings.py
然后这部分
# add your project directory to the sys.path
project_home = u'/home/rhpt'
需要
# add your project directory to the sys.path
project_home = u'/home/rhpt/myapp'
并保留此
os.environ['DJANGO_SETTINGS_MODULE'] = 'my_app.settings'
答案 1 :(得分:1)
也许你放空
__init__.py
与settings.py在同一文件夹中为我工作