Explanation of NoReverseMatch error in "python django super introduction"

Preface

While doing the text "python django super introduction" (Shuwa System), I entered the text exactly and an error occurred. There was no description in the errata provided by the publisher, so I posted it for study purposes. In the text I am creating a hello application.

Execution environment

django:3.0.2 python:3.7.4 OS:macOS Mojave 10.14.6

error contents

It happened when I was doing P.82 (moving multiple pages) on page 2-2.

index.html


<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="utf-8">
    <title>{{ title }}</title>
</head>
<body>
    <h1>{{ title }}</h1>
    <p>{{ msg }}</p>
    <p><a href="{% url goto %}">{{ goto }}</a></p>
</body>
</html>

views.py


#Before correction
# index()Only excerpt
def index(request):
    params = {
        'title': 'Hello/index',
        'msg': 'This is a sample page.',
        'goto': 'next',
    }
    return render(request, 'hello/index.html', params)

When accessing index.html in this state, the following error occurred.

NoReverseMatch at /hello/
Reverse for 'next' not found. 'next' is not a valid view function or pattern name.

What is "next"? ?? Is angry. .. ..

It's funny, no matter how many times I review it, it's as the text says. .. ..

Cause, solution

From the conclusion, it was due to the way'goto' was written in views.py. After modifying it as follows, it became normal.

views.py


#5th line
#Change before:
'goto': 'next',

#After change:
'goto': 'hello:next',

Execution result screen: 実行結果画面

The display of the link part is different from the text, but that is not the essence, so I will not touch it here. (Only "next" is supposed to be displayed in the text) The cause was that the template {% url goto%} part in index.html was not sent in the correct format. The format of the goto part should be'app name: name', but there was an inconsistency because only name came.

Afterword

The above is not described in the errata of Publisher support page, and I thought that some people would stumble on the same part, so I myself I posted it for the purpose of studying. I'm still studying django, so if you have any questions, please m (_ _) m

Recommended Posts

Explanation of NoReverseMatch error in "python django super introduction"
Introduction of Python
General Theory of Relativity in Python: Introduction
Introduction of Python
[Introduction to Python] Thorough explanation of the character string type used in Python!
Explanation of edit distance and implementation in Python
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
Equivalence of objects in Python
Introduction of activities applying Python
Design Patterns in Python: Introduction
Slice error in python (´ ; ω ; `)
Implementation of quicksort in Python
[For beginners] Summary of standard input in Python (with explanation)
Pixel manipulation of images in Python
8 Frequently Used Commands in Python Django
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
Implementation of login function in Django
Division of timedelta in Python 2.7 series
Handling of JSON files in Python
Implementation of life game in Python
Waveform display of audio in Python
Easy-to-understand explanation of Python Web application (Django) even for beginners (5) [Introduction to DB operation with Django shell]
Introduction of python drawing package pygal
The meaning of ".object" in Django
Law of large numbers in python
Implementation of original sorting in Python
Reversible scrambling of integers in Python
[Introduction] Insert line breaks in Python 3
Record of Python introduction for newcomers
Introduction to Python Django (2) Mac Edition
A super introduction to Django by Python beginners! Part 2 I tried using the convenient functions of the template
Easy-to-understand explanation of Python web application (Django) even for beginners (4) [Routing settings / Introduction to MTV design patterns]
Is_alive () gives an error instead of False after threading process in Python3
Easy-to-understand explanation of Python Web application (Django) even for beginners (2) [Project creation]
[Django] sqlite version error when running python manage.py in aws cloud9 environment
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
Conversion of string <-> date (date, datetime) in Python
[Introduction to Python] How to use class in Python?
Check the behavior of destructor in Python
The story of an error in PyOCR
(Bad) practice of using this in Python
Output tree structure of files in Python
Display a list of alphabets in Python 3
A super introduction to Python bit operations
Comparison of Japanese conversion module in Python3
[Illegal hardware instruction python] error in PyMC3
[Python] Understand the content of error messages
Easy introduction of speech recognition with Python
The result of installing python in Anaconda
Gang of Four (GoF) Patterns in Python
The basics of running NoxPlayer in Python
Bulk replacement of strings in Python arrays
Project Euler # 16 "Sum of Powers" in Python
Summary of built-in methods in Python list
Non-logical operator usage of or in python
Easy introduction of python3 series and OpenCV3
Practical example of Hexagonal Architecture in Python
Project Euler # 17 "Number of Characters" in Python
Double pendulum equation of motion in python
Introduction to Vectors: Linear Algebra in Python <1>
Get rid of DICOM images in Python