技术标签: Python django. Python-3.5
我想做的是让网站重定向到www(例如“example.com.“ 到 ”www.example.com.")
我用了 pip 安装 django_hosts.,然后跟着 文件 在网站上
这是我的 settings.py.py. 文件:
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.9.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://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 = False
ALLOWED_HOSTS = [
# 'example.com',
# 'www.example.com',
'*',
]
# Application definition
INSTALLED_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/#databases
DATABASES = {
'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-validators
AUTH_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 = True
USE_L10N = True
USE_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 settings
from django_hosts import patterns, host
host_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.middle.hostsrequestmiddlewaredjango';'django_hosts.middleware'不是包'
我究竟做错了什么?!
你在第一行结束时错过了逗号:
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',
]
错误: Select at least one project 或者 Invalid project description 为什么错? 要导入别人的项目,自作聪明的冒着风险把自己的项目删掉,把别人的项目放在自己的workplace里. 解决: 不要把要导入的项目放在自己的workplace...
环境 ubuntu16.04、dajngo2.0、uwsgi、nginx 部署开发的项目时 执行uwsgi的ini的配置文件时,报错 ,可以通过下面的方法解决 可以在uwsgi的配置文件ini中,添加一句话 pythonpath = /Users/work01/lib/python3.6/site-packages ( /Users/work01/lib/python3.6/s...
Django报如下错误: RuntimeError at /login You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard page ge...
TemplateDoesNotExist 开发第一个Templates的时候,TemplateDoesNotExist报错,找不到index.html文件 看了几篇博客都没能解决。 我的项目目录是这样子的 看错误原因: django.template.loaders.filesystem.Loader: F:\Django\mysite\templates\index....
Django运行错误:WinError 10013 1.问题描述: [WinError 10013]An attempt was made to access a socket in a way forbidden by its access 2.问题原因: 期望使用的端口已经被占用 3.解决方法: 更换使用端口 或参考下方链接关闭正在使用端口的进程 参考链接...
ALLOWED_HOSTS的作用 ALLOWED_HOSTS是用来设置允许哪些主机访问我们的django后台站点, 如果项目没有部署到远程服务器,且DEBUG = True(线下模式,允许调试),默认 有ALLOWED_HOSTS = [‘localhost’, ‘127.0.0.1’, ‘[::1]’],即默认允许本地主机访...
系统环境: 操作系统:RedHat EL5 Cluster: Oracle GI(Grid Infrastructure) Oracle: Oracle 11.2.0.1.0 如图所示:RAC 系统架构 对于Oracle 11G构建RAC首先需要构建GI(Grid Infrastructure)的架构 错误现象: 节点2运行root.sh脚本错误: [root@...
环境:win10 工具:pycharm 3.6 + python 3.6 + Django 2.0.7 打开pycharm。 File -> open。 选择Django项目。 点击Edit Configurations。 点击“ + ”,选择python。 根据自己的项目完成,选择与填写。 运行。...
背景: redis字典(hash表)当数据越来越多的时候,就会发生扩容,也就是rehash 对比:java中的hashmap,当数据数量达到阈值的时候(0.75),就会发生rehash,hash表长度变为原来的二倍,将原hash表数据全部重新计算hash地址,重新分配位置,达到rehash目的 redis中的hash表采用的是渐进式hash的方式: 1、redis字典(hash表)底层有...
2019独角兽企业重金招聘Python工程师标准>>> 我们平时按下键盘上的‘回车键’,就能实现回车换行【我们在屏幕上所看到的就是光标移到了下一行的开头位置!!ps:不讨论软件实现的特殊功能,如word里的回车智能缩进】。因此对这个按键更准确说应该叫做‘回车换行键’ 就且将这种将光标移到下行开...
I have a dataframe and i want to calculate the sum of variables present in a vector in every row and make the sum in other variable after i want the name of new variable created to be from the name of...
I have a very rough project that done partially in zend framework (not ZF2). The 'application', 'library' and 'public' folders are on the same root. Now i need to create a library 'Anil' in the 'libra...
I want to hide some of the categories from magento home page. I have created some categories like New Arrivals, Special Offer Which I would like to show in some different way may be in left panel or r...
I am writing to an internal file in Android Studio The code lets me write lines of data split with commas. I am able to then go to another activity and read it all out at once. However I want to be ab...
I'm new to Ruby On Rails, I used the acts_as_votable gem to create Like and Unlike Buttons to make Users like and unlike Posts but I can't make them change from Like to Unlike (and viceversa) and upda...