python – Django_Hosts导入错误

python – Django_Hosts导入错误,第1张

概述我想要做的是让网站重定向到www(例如“example.com”到“www.example.com”) 我使用pip来安装django_hosts,然后按照网站上的文档进行 *** 作 这是我的settings.py文件: """Django settings for mysite project.Generated by 'django-admin startproject' using Djan 我想要做的是让网站重定向到www(例如“example.com”到“www.example.com”)

我使用pip来安装django_hosts,然后按照网站上的文档进行 *** 作

这是我的settings.py文件:

"""Django settings for mysite project.Generated by 'django-admin startproject' using Django 1.9.For more information on this file,seehttps://docs.djangoproject.com/en/1.9/topics/settings/For the full List of settings and their values,seehttps://docs.djangoproject.com/en/1.9/ref/settings/"""import os# Build paths insIDe the project like this: os.path.join(BASE_DIR,...)BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Quick-start development settings - unsuitable for production# See https://docs.djangoproject.com/en/1.9/howto/deployment/checkList/# Security WARNING: keep the secret key used in production secret!SECRET_KEY = 'lsjz5tm#+0(99cv@mg=himl8=4w-vd^qq07jpd3d5278!hv06x'# Security WARNING: don't run with deBUG turned on in production!DEBUG = FalseALLOWED_HOSTS = [#    'example.com',#    'www.example.com','*',]# Application deFinitionINSTALLED_APPS = [    'RevIEws','Contact','Lessons','News','QNA','Home','About','Pupils','Website','django.contrib.admin','django.contrib.auth','django.contrib.ContentTypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',#third party    'django_hosts']MIDDLEWARE_CLASSES = [    'django_hosts.mIDdleware.HostsRequestMIDdleware'    'django.mIDdleware.security.SecurityMIDdleware','django.contrib.sessions.mIDdleware.SessionMIDdleware','django.mIDdleware.common.CommonMIDdleware','django.mIDdleware.csrf.CsrfVIEwMIDdleware','django.contrib.auth.mIDdleware.AuthenticationMIDdleware','django.contrib.auth.mIDdleware.SessionAuthenticationMIDdleware','django.contrib.messages.mIDdleware.MessageMIDdleware','django.mIDdleware.clickjacking.XFrameOptionsMIDdleware','django_hosts.mIDdleware.HostsResponseMIDdleware']ROOT_URLconf = 'mysite.urls'ROOT_HOSTCONF = 'mysite.hosts'DEFAulT_HOST = 'www'TEMPLATES = [    {        'BACKEND': 'django.template.backends.django.DjangoTemplates','Dirs': [],'APP_Dirs': True,'OPTIONS': {            'context_processors': [                'django.template.context_processors.deBUG','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},]Wsgi_APPliCATION = 'mysite.wsgi.application'# Database# https://docs.djangoproject.com/en/1.9/ref/settings/#databasesDATABASES = {    'default': {        'ENGINE': 'django.db.backends.sqlite3','name': os.path.join(BASE_DIR,'db.sqlite3'),}}# Password valIDation# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-valIDatorsAUTH_PASSWORD_VALIDATORS = [    {        'name': 'django.contrib.auth.password_valIDation.UserAttributeSimilarityValIDator',{        'name': 'django.contrib.auth.password_valIDation.MinimumLengthValIDator',{        'name': 'django.contrib.auth.password_valIDation.CommonPasswordValIDator',{        'name': 'django.contrib.auth.password_valIDation.NumericPasswordValIDator',]# Internationalization# https://docs.djangoproject.com/en/1.9/topics/i18n/LANGUAGE_CODE = 'en-us'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS,JavaScript,Images)# https://docs.djangoproject.com/en/1.9/howto/static-files/STATIC_URL = '/static/'EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'STATICfileS_Dirs = (    os.path.join('static'),)STATIC_ROOT = ''

这是我的hosts.py文件:

from django.conf import settingsfrom django_hosts import patterns,hosthost_patterns = patterns('',host(r'www',settings.ROOT_URLconf,name='www'),#host(r'(\w+)','path.to.custom_urls',name='wildcard'),)

当我运行python manage.py runserver时,我收到以下错误

django.core.exceptions.ImproperlyConfigured:无法加载Wsgi应用程序’mysite.wsgi.application’;导入模块时出错:’没有名为’django_hosts.mIDdleware.HostsRequestMIDdlewaredjango’的模块; ‘django_hosts.mIDdleware’不是包’

我究竟做错了什么?!

解决方法 你错过了一个逗号:

MIDDLEWARE_CLASSES = [    'django_hosts.mIDdleware.HostsRequestMIDdleware',# <-----    'django.mIDdleware.security.SecurityMIDdleware',]
总结

以上是内存溢出为你收集整理的python – Django_Hosts导入错误全部内容,希望文章能够帮你解决python – Django_Hosts导入错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1193865.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存