mysite / urls.py
from django.conf.urls import url,include
from django.contrib import admin
from django.contrib.auth import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', include('blog.urls')),
url(r'^accounts/login/$', views.login, name='login'),
url(r'^accounts/logout/$', views.logout,
name='logout', kwargs={'next_page': '/'}),
]
blog / urls.py
from django.conf.urls import include, url
from . import views
urlpatterns = [
url(r'^$',views.PostListView.as_view(),name='post_list'),
url(r'^about/$',views.AboutView.as_view(),name='about'),
url(r'^post/(?P<pk>\d+)/$', views.PostDetailView.as_view()
,name='post_detail'),
url(r'^post/new/$', views.CreatePostView.as_view(), name='post_new'),
url(r'^post/(?P<pk>\d+)/edit/$', views.PostUpdateView.as_view()
, name='post_edit'),
url(r'^drafts/$', views.DraftListView.as_view()
, name='post_draft_list'),
url(r'^post/(?P<pk>\d+)/remove/$', views.PostDeleteView.as_view()
,name='post_remove'),
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish
, name='post_publish'),
url(r'^post/(?P<pk>\d+)/comment/$', views.add_comment_to_post
, name='add_comment_to_post'),
url(r'^comment/(?P<pk>\d+)/approve/$', views.comment_approve
, name='comment_approve'),
url(r'^comment/(?P<pk>\d+)/remove/$', views.comment_remove
, name='comment_remove'),
]
当我尝试编辑,删除帖子,添加评论或从帖子中删除评论时发生错误
我无法访问blog/urls.py
中的任何网址
而且我不知道错误是从哪里来的。
答案 0 :(得分:1)
在您的模板中,您有一个链接,您在其中错过了URL标记中的%
。你有类似的东西,
{ url 'post_detail' pk=post.pk }
但是应该是:
{% url 'post_detail' pk=post.pk %}
当您单击无效链接时,它将带您到drafts/{url 'post_detail' pk=post.pk}
,因此您会收到404错误。