我的设置
将django项目部署到运行Ubunto 12.04的服务器时,我发现在我的INSTALLED_APPS
文件的settings.py
部分列出了一个额外但不存在的应用程序阻止我使用任何{ {1}}命令。
python manage.py
在这种情况下,我之前在项目中有一个INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'survey',
'django_countries',
)
应用程序,我随后将其删除。但是,这从未阻止我能够使用本地计算机django_countries
上的任何python manage.py
命令
然而,当我将项目上传到我的生产服务器时,它会给我错误,例如正在运行OSX 10.9.3
会得到我
python manage.py runserver
当然,移除$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named django_countries
中不必要的django_countries
应用已解决了我的问题,但我想知道:为什么两种环境之间存在差异?我应该注意哪些其他重大差异?
答案 0 :(得分:0)
这是一个完全预期的行为 - INSTALLED_APPS
定义了您安装的应用程序,Django尝试找到他们的模型,网址等。如果找不到任何已安装,你会收到这个错误。从INSTALLED_APPS
中删除它或安装它。
此外,您似乎不使用VirtualEnv。学习如何使用它并将其用于每个项目,否则你很快就会疯了。)