Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1种模式:[';posts/(?P<;pk>;[0-9]+;)/$&&x27;]_Python_Django - Fatal编程技术网

Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1种模式:[';posts/(?P<;pk>;[0-9]+;)/$&&x27;]

Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1种模式:[';posts/(?P<;pk>;[0-9]+;)/$&&x27;],python,django,Python,Django,我正在构建一个django博客应用程序。但是,当我试图为博客文章构建详细页面时,我遇到了以下错误: NoReverseMatch at / Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['posts/(?P<pk>[0-9]+)/$'] 我的url路径: path('posts/<int:post_id>/',views.post_detail,name='deta

我正在构建一个django博客应用程序。但是,当我试图为博客文章构建详细页面时,我遇到了以下错误:

NoReverseMatch at /
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['posts/(?P<pk>[0-9]+)/$']
我的url路径:

path('posts/<int:post_id>/',views.post_detail,name='detail'),
path('posts/',views.post_detail,name='detail'),
以及链接到详细信息页面的行:

<p class="lead my-3"><a href="{% url 'blog:detail' post.id %}" class="text-white font-weight-bold">{{ latest_post.title }}</a></p>

我认为我不应该在这方面有任何错误。我哪里做错了

编辑


我解决了这个问题。只是当我试图将这个“细节”链接添加到“最新发布”变量时。但我只为“post”变量指定了它。我刚刚用“post”替换了它,它成功了

您试图访问的URL是什么?我在问题中指定的是我的URL。我在浏览器上的意思是,你在那里输入的完整地址是什么?哦,那个。它的“localhost:8000/posts/1/”。url中的1根据id的不同而不同。还有一件事。当我手动转到“localhost:8000/posts/1/”时,我没有得到任何错误并看到预期的输出。但是,当我尝试向该页面添加链接时,我看到了“NoReverseMatch”错误。
<p class="lead my-3"><a href="{% url 'blog:detail' post.id %}" class="text-white font-weight-bold">{{ latest_post.title }}</a></p>