我正在使用Python-Django开发博客。当我运行命令" python manage.py runserver"在我的项目文件夹中,我收到以下错误:
Traceback (most recent call last):
File "manage.py", line 6, in <module>
server = request.META.get('wsgi.file_wrapper', None)
AttributeError: 'module' object has no attribute 'META'
我没有在任何地方看到这个错误。我应该在instal_apps中包含Meta类吗?我该怎么做?
这是我的manage.py:
#!/usr/bin/env python
import os
import sys
from django.http import request
server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print('inside dev')
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj1.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
和settings.py:
"""
Django settings for dj1 project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(l8*%h2ids25q=x9qb7%x+(b=$1mm&yg8b5ga^0u2w9*+k%+9-'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
MIDDLEWARE_CLASSES = (
'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',
)
ROOT_URLCONF = 'dj1.urls'
WSGI_APPLICATION = 'dj1.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/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.7/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
答案 0 :(得分:1)
这真是一个很大的代码扩展器。
这段代码在manage.py
中没有任何意义from django.http import request
server = request.META.get('wsgi.file_wrapper', None)
if server is not None and server.__module__ == 'django.core.servers.basehttp':
print('inside dev')
也许你是从某个地方复制过来的,并没有把它放在它所属的地方。
这件作品属于一种观点。它永远不会在manage.py中运行,并且在那里毫无意义。
[编辑]
另外,在视图中,您应 NOT 包含导入,否则您将收到相同的错误。这意味着,不要包含此from django.http import request