SalahAdDin SalahAdDin - 1 month ago 24
Python Question

Custom settings and wsgi in django 1.10 give me error

I have this bug with custom settings running the server:

salahaddin@TulipanROG  ~/Proyectos/tiempoturco/tiempoturco  (tiempoturco)  ./manage.py runserver  ✓  640  23:22:06
Performing system checks...

System check identified no issues (0 silenced).
June 19, 2016 - 23:22:07
Django version 1.10a1, using settings 'tiempoturco.settings.dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f288d67f2f0>
Traceback (most recent call last):
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
handler = self.get_handler(*args, **options)
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super(Command, self).get_handler(*args, **options)
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
return import_string(app_path)
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/salahaddin/Proyectos/tiempoturco/tiempoturco/tiempoturco/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
self.load_middleware()
File "/home/salahaddin/Proyectos/tiempoturco/lib/python3.5/site-packages/django/core/handlers/base.py", line 79, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters


I have this folder structure:
enter image description here

And here my wsgi code:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tiempoturco.settings.dev")

application = get_wsgi_application()


And my manage.py code:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tiempoturco.settings.dev")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)


What is wrong?
I can execute migrations and create super users, use the shell plus and other commands but i can run the server. I tried change the setting value to production and dev, putting this values in
__init__.py
and doing other thins but nothing.

And
middleware_clases
:

MIDDLEWARE_CLASSES = [
'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',
]


I can't find information about this and i'm testing
django 1.10
.

I haven't problems with django
1.9.7
, i don't know why. In same way, when i create a project with
wagtail 1.6
i haven't problem in runserver,
wagtail 1.6
installs
django 1.9.7
yet, but i replace then it for
django 1.10
and then try to run the project after run migrations and create a super user, and when i go to the home in the browser i can see the page, and admin too.

So, i haven't problems with use other app, but create handly multiple settings myself give me this bug yet.

Can anyone help me?

mol mol
Answer

try changing the MIDDLEWARE_CLASSES

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',
    'django.middleware.security.SecurityMiddleware',
]
Comments