import error django corsheaders

2020-06-06 17:30发布

i am a beginner in django. i am doing project based on it. project has two stages. i completed first phase and uploaded the code to amazon ec2 instance. after completing second phase i added some packages like python-social-auth, django-cors-headers, django-easy-maps, crispyforms. but now it is showing import error for corsheaders and this the traceback i have checked virtual environment and corsheaders package is ther

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

any suggestions please

4条回答
霸刀☆藐视天下
2楼-- · 2020-06-06 18:01

From your traceback, it looks like you are not running the Django app in virtual environment. You could do two things:

  1. Install django-corsheaders system wide so it's available to your app, with or without virtual environment

  2. Or you activate the virtual environment and run the django app (since you have already confirmed that django-corsheaders is installed in virtual environment.)

查看更多
何必那么认真
3楼-- · 2020-06-06 18:04

I had the same problem after installed via pip. Then i downloaded source and manually installed the django-cors-headers after that the problem was gone.

Hope that helps.

查看更多
趁早两清
4楼-- · 2020-06-06 18:05

Try This.

pip install --user django-cors-headers
查看更多
混吃等死
5楼-- · 2020-06-06 18:20

Using pip :

pip install django-cors-headers

Using pipenv :

pipenv install django-cors-headers
查看更多
登录 后发表回答