Wagtail博客中找不到标签:Django使用mysite.urls中定义的URLconf尝试了这些URL模式



我正在学习Wagtail v2.4教程,并在博客中添加了标记功能。然而,当我点击博客文章上的标签链接时,我会得到一个404错误。标签索引页面(/tags/)显示所有没有任何标签的帖子。我只创建了一个带有标签的帖子。

未找到页面(404)

请求方法:GET

请求URL:http://localhost:8000/tags/tag%3Dnewswithimages

Django使用koamrn.uls中定义的URLconf尝试了以下URL模式,顺序如下:

  1. ^django管理员/
  2. ^管理员/
  3. ^文件/
  4. ^search/$[name='search']
  5. ^_util/authenticate_with_password/(\d+)/(\d+)/$[name='agtailcore_authenticate_with_password']
  6. ^_util/login/$[name='agtailcore_login']
  7. ^((?:[\w-]+/)*)$[name='agtail_server']
  8. ^静态/(?P.*)$
  9. ^媒体/(?P.*)$

当前路径tags/tag=newswithinemages与其中任何一个都不匹配。

我想我需要在urls.py中添加一个路径?

from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from search import views as search_views
urlpatterns = [
url(r'^django-admin/', admin.site.urls),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^search/$', search_views.search, name='search'),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
url(r'', include(wagtail_urls)),
# Alternatively, if you want Wagtail pages to be served from a subpath
# of your site, rather than the site root:
#    url(r'^pages/', include(wagtail_urls)),
]

if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Serve static and media files from development server
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

news_tag_index_page.html:

{% extends "base.html" %}
{% load wagtailcore_tags %}
{% block content %}
{% if request.GET.tag|length %}
<h4>Showing pages tagged "{{ request.GET.tag }}"</h4>
{% endif %}
{% for newspage in newspages %}
<p>
<strong><a href="{% pageurl newspage %}">{{ newspage.title }}</a></strong><br />
<small>Revised: {{ newspage.latest_revision_created_at }}</small><br />
{% if newspage.author %}
<p>By {{ newspage.author.profile }}</p>
{% endif %}
</p>
{% empty %}
No pages found with that tag.
{% endfor %}
{% endblock %}
标签列表页面的URL应该是/tags?tag=newswithimages,而不是tags/tag=newswithimages。很可能,您在blog_page.html:上的链接中出现了拼写错误
<a href="{% slugurl 'tags' %}?tag={{ tag }}"><button type="button">{{ tag }}</button></a>

您只需要继续阅读教程:)

"访问带有标签的博客文章现在应该在底部显示一组链接按钮,每个标签一个。但是,单击按钮会得到404,因为我们还没有定义"标签"视图。">

https://docs.wagtail.io/en/v2.4/getting_started/tutorial.html#tagging-张贴

相关内容

最新更新