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

2024-04-20 07:06:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

  {{ commentform | as_bootstrap }}

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

这是URL模式:

^{pr2}$

以下是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.

我尝试了不同的组合,因为我是新的正则表达式,但我不能让它工作。在


Tags: djangonameinformaddurl表单错误