2014-12-13 97 views
-1

我正在Python-Django的博客上工作。當我運行在我的項目文件夾中的命令「蟒蛇manage.py runserver命令」,我得到以下錯誤:AttributeError:'module'對象在Django項目中沒有屬性'META'

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' 

我還沒有看到這個錯誤在任何地方。我應該在我的installed_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

你知道這段代碼的原意是什麼嗎?據我所知,你想看看哪個服務器正在運行你的django代碼。如果你仍然想要,或者有其他的想法,你可以編輯你的問題,我會盡力協助。 – 2014-12-14 11:25:59

回答

1

這確實是一個很大的代碼製作工具的詳情。

這段代碼在這裏是沒有意義的

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裏面,並沒有把它放在屬於它的地方。

這件coude屬於視圖。它不會在manage.py內工作,並且在那裏毫無意義。

[編輯] 此外,在視圖中,你應該包括進口,否則你會得到同樣的錯誤。也就是說,不包括這個from django.http import request

相關問題