user1743439
user1743439

Reputation: 43

AttributeError: 'module' object has no attribute 'META' in Django Project

I am working on a blog in Python-Django. When I run the command "python manage.py runserver" in my project folder, I get following error:

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'

I have not seen this error anywhere. Should I include Meta class in my installed_apps? How do I do it?

Here is my 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)

and 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'),
)

Upvotes: 0

Views: 5774

Answers (1)

vlad-ardelean
vlad-ardelean

Reputation: 7622

This is really a big code bulder.

This piece of code here makes no sense inside the 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')

Perhaps you copied it from somewhere, and didn't put it where it belongs.

This piece of coude would belong in a view. It will never work inside manage.py, and makes asolutely no sense there.

[EDIT] ALSO, in a view, you should NOT include the import, or you'll get the same error. That means, don't include this from django.http import request

Upvotes: 1

Related Questions