rik_maz
rik_maz

Reputation: 69

Facing trouble in running python manage.py runserver

I am trying to run python manage.py runserver and till today I never faced any issues. Whenever I run python manage.py runserver I get this-

$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
August 11, 2019 - 05:34:42
Django version 2.1.5, using settings 'try_django.settings'
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 0x7f0b20e6d6a8>
Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.7/site-packages/django/utils/module_loading.py", line 13, in import_string
module_path, class_name = dotted_path.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
return import_string(app_path)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/home/user/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/user/Dev/try_django_new/src/try_django/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 136, in __init__
self.load_middleware()
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/handlers/base.py", line 34, in load_middleware
middleware = import_string(middleware_path)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/utils/module_loading.py", line 15, in import_string
raise ImportError("%s doesn't look like a module path" % dotted_path) from err
ImportError: blog doesn't look like a module path

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 137, in inner_run
handler = self.get_handler(*args, **options)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "/home/user/anaconda3/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 50, in get_internal_wsgi_application
) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'try_django.wsgi.application' could not be loaded; Error importing module.

I looked for solutions and found out that in the settings.py file I should change WSGI_APPLICATION = 'application' to WSGI_APPLICATION = 'wsgi.application' but it was already so in my settings.py file.

Upvotes: 0

Views: 2183

Answers (2)

teraspora
teraspora

Reputation: 442

Django's server needs to find your application as defined in wsgi.py, so you need to set `WSGI_APPLICATION = '<project-name>.wsgi.application'.

See the docs at https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/

which state:

WSGI servers obtain the path to the application callable from their configuration. Django’s built-in server, namely the runserver command, reads it from the WSGI_APPLICATION setting. By default, it’s set to <project_name>.wsgi.application, which points to the application callable in <project_name>/wsgi.py.

Upvotes: 0

azundo
azundo

Reputation: 6052

Based on the error it looks like you have an entry of simply 'blog' in your MIDDLEWARE settings. Django middleware requires a path to a class so 'blog' is not a valid value.

That's based on these lines from your traceback:

middleware = import_string(middleware_path)
File "/home/user/anaconda3/lib/python3.7/site-packages/django/utils/module_loading.py", line 15, in import_string
raise ImportError("%s doesn't look like a module path" % dotted_path) from err
ImportError: blog doesn't look like a module path

Upvotes: 2

Related Questions