我想在Django中開發一個示例項目,並在運行syncdb命令時出現錯誤。ImportError:無法導入設置
這是我的項目結構看起來像:
/用戶/ django_demo/godjango /預訂:
manage.py
registration/
forms.py
views.py
models.py
urls.py
bookings/
settings.py
urls.py
我的manage.py文件如下:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我的PYTHONPATH和DJANGO_SETTINGS_MODULE設置如下
$echo $DJANGO_SETTINGS_MODULE
bookings.settings
$ echo $PYTHONPATH
/Users/django_demo/godjango/bookings
而且我WSGI.py文件看起來像如下:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
當我運行了Python manage.py執行syncdb命令,我收到以下錯誤。
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Users/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'bookings.settings' (Is it on sys.path?): No module named unipath
有人可以建議我失蹤了嗎?
怎樣才能「動」我的應用程序進入路徑之一? – Timo
@Timo:如果你使用virtualenv,你可以使用命令'add2virtualenv' – jnns
,任何人都可以幫助我解決這個問題。我也面對這樣的錯誤。 http://stackoverflow.com/questions/33890277/deploy-django-on-apache?noredirect=1#comment55585809_33890277仍然無法解決。 – uma