Django 3.2.7 - NoReverseMatch at /blog/ Reverse for ' latest_posts' not found. ' latest_posts' не является допустимой функцией представления или именем шаблона
Следуя руководству из "Coding For Everybody - Learn wagtail", я столкнулся с проблемой при работе с видео Routable Pages. Я скопировал код, найденный на его GitHub, в свой блог и теперь появляется следующая ошибка:
Reverse for ' latest_posts' not found. ' latest_posts' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://localhost:8000/blog/
Django Version: 3.2.7
Exception Type: NoReverseMatch
Exception Value:
Reverse for ' latest_posts' not found. ' latest_posts' is not a valid view function or pattern name.
Exception Location: C:\Users\pedro.garcia\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py, line 694, in _reverse_with_prefix
Python Executable: C:\Users\pedro.garcia\AppData\Local\Programs\Python\Python39\python.exe
Python Version: 3.9.6
Python Path:
['C:\\Users\\pedro.garcia\\website\\mysite',
'C:\\Users\\pedro.garcia\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip',
'C:\\Users\\pedro.garcia\\AppData\\Local\\Programs\\Python\\Python39\\DLLs',
'C:\\Users\\pedro.garcia\\AppData\\Local\\Programs\\Python\\Python39\\lib',
'C:\\Users\\pedro.garcia\\AppData\\Local\\Programs\\Python\\Python39',
'C:\\Users\\pedro.garcia\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages']
Server time: Fri, 15 Oct 2021 13:28:15 +0000
Мои последние_посты.html:
{% extends "base.html" %}
{% load wagtailimages_tags %}
{% block content %}
<div class="container">
<h1>Latest Posts</h1>
{% for post in posts %}
<div class="row mt-5 mb-5">
<div class="col-sm-3">
{% image post.blog_image fill-250x250 as blog_img %}
<a href="{{ post.url }}">
<img src="{{ blog_img.url }}" alt="{{ blog_img.alt }}">
</a>
</div>
<div class="col-sm-9">
<a href="{{ post.url }}">
<h2>{{ post.custom_title }}</h2>
{# @todo add a summary field to BlogDetailPage; make it a RichTextField with only Bold and Italic
enabled. #}
<a href="{{ post.url }}" class="btn btn-primary mt-4">Read More</a>
</a>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
my base.html:
Мой блог_листинг_страницы.html:
{% extends "base.html" %}
{% load wagtailimages_tags wagtailroutablepage_tags %}
{% block content %}
<a href="{% routablepageurl page " latest_posts" %}">View Latest Posts Only</a>
<h2>
Categories:
<small>
{% for cat in categories %}
<a href="?category={{ cat.slug }}">
{{ cat.name }}
</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</small>
</h2>
<div class="container">
{% for post in posts %}
<div class="row mt-5 mb-5">
<div class="col-sm-3">
{% image post.blog_image fill-250x250 as blog_img %}
<a href="{{ post.url }}">
<img src="{{ blog_img.url }}" alt="{{ blog_img.alt }}">
</a>
</div>
<div class="col-sm-9">
<a href="{{ post.url }}">
<h2>{{ post.custom_title }}</h2>
{# @todo add a summary field to BlogDetailPage; make it a RichTextField with only Bold and Italic
enabled. #}
<a href="{{ post.url }}" class="btn btn-primary mt-4">Read More</a>
</a>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
Я пытался повторить все шаги, смотрел видео снова и снова, но ничего не помогло.
В строке
{% routablepageurl page " latest_posts" %}
у вас есть пробел перед latest_posts
- вы должны удалить его.
Само сообщение об ошибке указывает на то, что искомое пространство имен url не существует ' latest_posts'
Смотрите здесь :-
Reverse for ' latest_posts' not found. ' latest_posts' is not a valid view function or pattern name.
Если вы проверите в своем файле urls.py, вы найдете правильное пространство имен, которое вы можете использовать в этом месте.
На данный момент проблема находится в файле My blog_listing_page.html
.