【发布时间】:2019-01-29 06:11:43
【问题描述】:
我正在关注Wagtail v2.4 tutorial 并向博客添加了标记功能。但是,当我单击博客文章上的标签链接时,我收到 404 错误。标签索引页面 (/tags/) 显示所有没有任何标签的帖子。我只创建了一个带有标签的帖子。
找不到页面 (404)
请求方法:GET
请求网址:http://localhost:8000/tags/tag%3Dnewswithimages
使用 koamrn.urls 中定义的 URLconf,Django 按以下顺序尝试了这些 URL 模式:
- ^django-admin/
- ^admin/
- ^文档/
- ^search/$ [name='search']
- ^_util/authenticate_with_password/(\d+)/(\d+)/$[name='wagtailcore_authenticate_with_password']
- ^_util/login/$ [name='wagtailcore_login']
- ^((?:[\w-]+/)*)$ [name='wagtail_serve']
- ^static/(?P.*)$
- ^media/(?P.*)$
当前路径 tags/tag=newswithimages 与其中任何一个都不匹配。
我猜我需要在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 %}
【问题讨论】:
标签: wagtail