PacktPublishing / Django-3-by-Example

Django 3 by Example (3rd Edition) published by Packt
https://djangobyexample.com/
MIT License
717 stars 687 forks source link

Chapter 10: NoReverseMatch at /course/module/1/ #71

Closed mjavadf closed 3 years ago

mjavadf commented 3 years ago

Traceback message:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/course/module/1/

Django Version: 3.1.7
Python Version: 3.9.1
Installed Applications:
['course.apps.CourseConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error:
In template G:\Workspace\new-educa\educa\templates\base.html, error at line 0
   Reverse for 'module_order' not found. 'module_order' is not a valid view function or pattern name.
   1 : {% load static %}
   2 : <!DOCTYPE html>
   3 : <html lang="en">
   4 : <head>
   5 :   <meta charset="utf-8" />
   6 :   <title>{% block title %}Educa{% endblock %}</title>
   7 :   <link href="{% static "css/base.css" %}" rel="stylesheet">
   8 : </head>
   9 : <body>
   10 :   <div id="header">

Traceback (most recent call last):
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
    response = response.render()
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\response.py", line 105, in render
    self.content = self.rendered_content
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 170, in render
    return self._render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 162, in _render
    return self.nodelist.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 162, in _render
    return self.nodelist.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\template\defaulttags.py", line 446, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\urls\base.py", line 87, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "G:\Workspace\new-educa\educa\venv\lib\site-packages\django\urls\resolvers.py", line 685, in _reverse_with_prefix
    raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /course/module/1/
Exception Value: Reverse for 'module_order' not found. 'module_order' is not a valid view function or pattern name.
pythonyalfa commented 3 years ago

Looks like you may need to add the view to your application go back the 2 or 3 rd chapter to understand how the views.py needs to be created or modified for your applications. IM still learning myself so I may be wrong but the error itself says it.