URL与Django中的任何url模式都不匹配

时间:2017-11-27 19:11:12

标签: python django

我正在尝试创建一个博客来学习Django。我想在博文中添加评论部分。现在,当我在评论表单中单击提交时,我在URL模式中使用的正则表达式出现了无匹配错误。但是,当我在pythex上尝试正则表达式时,它似乎匹配在我单击提交按钮后重定向的结果URL。 这是我的HTML表单:

    <form id ="post_form" method = "post" action = "add_comment/">

  {{ commentform | as_bootstrap }}

  <input type = "submit" name = "submit" value = "Create Comment">

这是网址格式:

from django.conf.urls import url, include
from blog import views

    urlpatterns = [
        url(r'^$', views.index, name = 'index'),
        url(r'^add_post/', views.add_post, name = 'add_post'),
        url(r'^(?P<slug>[\w|\-]+)/$', views.post, name = 'post'),
        url(r'^(?P<slug>[\w|\-]+])/add_comment/$', views.add_comment, name = 'add_comment')
    ]

这是django上的错误消息:

Page not found (404)
Request Method: POST
Request URL:    http://localhost:8000/blog/title-3/add_comment/
Using the URLconf defined in bloggy_project.urls, Django tried these URL patterns, in this order:
^admin/
^blog/ ^$ [name='index']
^blog/ ^add_post/ [name='add_post']
^blog/ ^(?P<slug>[\w|\-]+)/$ [name='post']
^blog/ ^(?P<slug>[\w|\-]+])/add_comment/$ [name='add_comment']
^media/(?P<path>.*)$

The current URL, blog/title-3/add_comment/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

我尝试了不同的组合,因为我是regex的新手,但是我无法让它工作。

0 个答案:

没有答案