【问题标题】:pythonanywhere corsheaders module not found errorpythonanywhere corsheaders 模块未找到错误
【发布时间】:2020-11-10 07:40:59
【问题描述】:

我设置如下,但有错误。 我需要你的帮助。

  1. 在setting.py文件中设置corsheader
  2. pip install django-cors-headers 已安装。
  3. 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: 
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: 
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)

【问题讨论】:

    标签: python pythonanywhere modulenotfounderror


    【解决方案1】:

    您的 Web 应用程序在虚拟环境 myvenv 中运行,但您在 .local 中安装了带有 --user 标志的包。您需要在没有--user 的情况下安装它并激活myvenv 虚拟环境。见:https://help.pythonanywhere.com/pages/InstallingNewModules/

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 2019-03-25
      • 1970-01-01
      • 2019-02-18
      • 1970-01-01
      • 2018-11-05
      • 2019-01-15
      • 2015-06-03
      • 2019-01-25
      相关资源
      最近更新 更多