在 Wagtail 博客中找不到标签:使用 mysite.urls 中定义的 URLconf,Django 尝试了这些 URL 模式
Tags not found in Wagtail Blog: Using the URLconf defined in mysite.urls, Django tried these URL patterns
我正在关注 Wagtail v2.4 tutorial 并向博客添加了标记功能。但是,当我单击博客 post 上的标签 link 时,出现 404 错误。标签索引页面 (/tags/
) 显示所有 post 没有任何标签。我只创建了一个带标签的 post。
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/tags/tag%3Dnewswithimages
Using the URLconf defined in koamrn.urls, Django tried these URL patterns, in this order:
- ^django-admin/
- ^admin/
- ^documents/
- ^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.*)$
The current path, tags/tag=newswithimages, didn't match any of these.
我想我需要在 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 %}
您只需要继续阅读教程:)
"Visiting a blog post with tags should now show a set of linked buttons at the bottom - one for each tag. However, clicking a button will get you a 404, since we haven’t yet defined a “tags” view."
https://docs.wagtail.io/en/v2.4/getting_started/tutorial.html#tagging-posts
标签列表页面的 URL 应该是 /tags?tag=newswithimages
,而不是 tags/tag=newswithimages
。很可能,您在 blog_page.html
上的 link 中打错了字:
<a href="{% slugurl 'tags' %}?tag={{ tag }}"><button type="button">{{ tag }}</button></a>
我正在关注 Wagtail v2.4 tutorial 并向博客添加了标记功能。但是,当我单击博客 post 上的标签 link 时,出现 404 错误。标签索引页面 (/tags/
) 显示所有 post 没有任何标签。我只创建了一个带标签的 post。
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/tags/tag%3Dnewswithimages
Using the URLconf defined in koamrn.urls, Django tried these URL patterns, in this order:
- ^django-admin/
- ^admin/
- ^documents/
- ^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.*)$
The current path, tags/tag=newswithimages, didn't match any of these.
我想我需要在 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 %}
您只需要继续阅读教程:)
"Visiting a blog post with tags should now show a set of linked buttons at the bottom - one for each tag. However, clicking a button will get you a 404, since we haven’t yet defined a “tags” view."
https://docs.wagtail.io/en/v2.4/getting_started/tutorial.html#tagging-posts
标签列表页面的 URL 应该是 /tags?tag=newswithimages
,而不是 tags/tag=newswithimages
。很可能,您在 blog_page.html
上的 link 中打错了字:
<a href="{% slugurl 'tags' %}?tag={{ tag }}"><button type="button">{{ tag }}</button></a>