Studying recently Django, Follow up with one Django From building to deploying the forum , Tutorial links are also posted :【 The first part -django From building to deploying the forum 】 A complete Django Getting started - Dark cloud crossing , There is a problem in the third part , It's been bothering me for a long time . After consulting, it is still fruitless , After reading the official documents, the problem still hasn't been solved , Then I suddenly found the problem , Let's take a look at the error reporting , It's true that I made a mistake when I wrote it . First post the error information :
Internal Server Error: /boards/1/Traceback (most recent call last): File “D:\IDE\Python\Anaconda\lib\site-packages\django\core\handlers\exception.py”, line 34, in inner response = get_response(request) File “D:\IDE\Python\Anaconda\lib\site-packages\django\core\handlers\base.py”, line 126, in _get_response response = self.process_exception_by_middleware(e, request) File “D:\IDE\Python\Anaconda\lib\site-packages\django\core\handlers\base.py”, line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File “D:\IDE\pycharm\PyCharm Community Edition 2018.1.2\DjangoProjects\myproject\boards\views.py”, line 33, in board_topics return render(request, ‘topics.html’, {‘board’: board}) File “D:\IDE\Python\Anaconda\lib\site-packages\django\shortcuts.py”, line 36, in render content = loader.render_to_string(template_name, context, request, using=using) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\loader.py”, line 62, in render_to_string return template.render(context, request) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\backends\django.py”, line 61, in render return self.template.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 171, in render return self._render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 163, in _render return self.nodelist.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 937, in render bit = node.render_annotated(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 904, in render_annotated return self.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\loader_tags.py”, line 150, in render return compiled_parent._render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 163, in _render return self.nodelist.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 937, in render bit = node.render_annotated(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 904, in render_annotated return self.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\loader_tags.py”, line 62, in render result = block.nodelist.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 937, in render bit = node.render_annotated(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 904, in render_annotated return self.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\loader_tags.py”, line 62, in render result = block.nodelist.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 937, in render bit = node.render_annotated(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\base.py”, line 904, in render_annotated return self.render(context) File “D:\IDE\Python\Anaconda\lib\site-packages\django\template\defaulttags.py”, line 442, in render url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app) File “D:\IDE\Python\Anaconda\lib\site-packages\django\urls\base.py”, line 90, in reverse return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File “D:\IDE\Python\Anaconda\lib\site-packages\django\urls\resolvers.py”, line 622, in _reverse_with_prefix raise NoReverseMatch(msg)django.urls.exceptions.NoReverseMatch: Reverse for ‘new_topic’ not found. ‘new_topic’ is not a valid view function or pattern name.[24/Nov/2018 22:54:00] “GET /boards/1/ HTTP/1.1” 500 169427
It looks a bit messy , In fact, the key message is the last sentence :
Reverse for ‘new_topic’ not found . ‘new_topic’ is not a valid view function or pattern name.
It means new_topic It was not found in the analysis ,‘new_topic’ Is not a valid view method or schema name .
The errors reported by the browser are also posted :
urls.py:
view.py:
I noticed that it was urls.py The namespace in the file is written incorrectly :
Actually, I'm view.py The method defined in the file is new_topic,HTML Template naming is also new_topic.html, So I added one more s Led to a mistake . You still need to be more careful in the future .