如何解决pythonanywhere corsheaders模块未找到错误
我将其设置如下,但是出现错误。 我需要你的帮助。
- 在setting.py文件中设置corsheader
- 已安装pip install django-cors-headers。
- pip3 install django-cors-head已安装。
即使我们按照上面的方法进行处理,也存在如下错误。
2020-11-10 07:10:05,116: ***************************************************
2020-11-10 07:10:05,117: If you're seeing an import error and don't know why,2020-11-10 07:10:05,117: we have a dedicated help page to help you debug:
2020-11-10 07:10:05,117: https://help.pythonanywhere.com/pages/DebuggingImportError/
2020-11-10 07:10:05,117: ***************************************************
2020-11-10 16:11:05,533: Error running WSGI application
2020-11-10 16:11:05,542: ModuleNotFoundError: No module named 'corsheaders'
2020-11-10 16:11:05,543: File "/var/www/abc_com_wsgi.py",line 16,in <module>
2020-11-10 16:11:05,543: application = get_wsgi_application()
2020-11-10 16:11:05,543:
2020-11-10 16:11:05,543: File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/core/wsgi.py",line 12,in get_wsgi_application
2020-11-10 16:11:05,543: django.setup(set_prefix=False)
2020-11-10 16:11:05,543: File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/__init__.py",line 24,in setup
2020-11-10 16:11:05,543: apps.populate(settings.INSTALLED_APPS)
2020-11-10 16:11:05,544:
2020-11-10 16:11:05,544: File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/apps/registry.py",line 91,in populate
2020-11-10 16:11:05,544: app_config = AppConfig.create(entry)
2020-11-10 16:11:05,544: File "/home/abc/adm/adm/myvenv/lib/python3.7/site-packages/django/apps/config.py",line 90,in create
2020-11-10 16:11:05,544: module = import_module(entry)
setting.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
ALLOWED_HOSTS = [u'abc.com','aa.abc.com',]
INSTALLED_APPS = [
'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','corsheaders',]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','corsheaders.middleware.CorsMiddleware',]
pip3 cors-headers安装命令
pip3.7 install --user django-cors-headers
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: django-cors-headers in ./.local/lib/python3.7/site-packages (3.3.0)
Requirement already satisfied: Django>=2.0 in /usr/lib/python3.7/site-packages (from django-cors-headers) (2.1)
Requirement already satisfied: pytz in /usr/lib/python3.7/site-packages (from Django>=2.0->django-cors-headers) (2018.5)
解决方法
您的Web应用程序在虚拟环境myvenv
中运行,但是您已使用.local
标志将软件包安装在--user
中。您需要在未激活--user
虚拟环境的myvenv
的情况下安装它。参见:https://help.pythonanywhere.com/pages/InstallingNewModules/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。