导入错误django corsheaders

时间:2014-09-27 07:34:13

标签: python django amazon-ec2 django-cors-headers

我是django的初学者。我正在做基于它的项目。项目有两个阶段。我完成了第一阶段并将代码上传到amazon ec2实例。完成第二阶段后,我添加了一些包,如python-social-authdjango-cors-headersdjango-easy-mapscrispyforms。但现在它显示了corsheaders的导入错误和这个追溯 我检查了虚拟环境和corsheaders包是否

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 corsheaders

请提出任何建议

5 个答案:

答案 0 :(得分:61)

使用pip

pip install django-cors-headers

使用pipenv

pipenv install django-cors-headers

答案 1 :(得分:1)

您不需要安装任何东西,只需使用runserver

python manage.py runserver

答案 2 :(得分:0)

通过pip安装后我遇到了同样的问题。然后我下载了源代码并在问题消失后手动安装了django-cors-headers

希望有所帮助。

答案 3 :(得分:0)

您的设置可能有误。

INSTALLED_APPS = [
    "corsheaders"
    
]

答案 4 :(得分:-2)

从您的回溯中,您似乎没有在虚拟环境中运行Django应用程序。你可以做两件事:

  1. 在系统范围内安装django-corsheaders,以便您的应用可以使用或不使用虚拟环境

  2. 或者您激活虚拟环境并运行django应用程序(因为您已经确认在虚拟环境中安装了django-corsheaders。)