在django中实现slug url时我做错了什么?

时间:2022-02-07 07:33:19

I am getting the following error after I modified the urls.py, views.py and models.py file in my blog application to accomodate a slug string in the url.

我修改了我的博客应用程序中的urls.py,views.py和models.py文件后,我收到以下错误,以容纳url中的slug字符串。

Reverse for 'post_detail' with keyword arguments '{'pk': 3}' not found. 1 pattern(s) tried: ['(?P[-\w\d]+),(?P\d+)/$']

使用关键字参数'{'pk':3}'找不到“post_detail”。尝试了1种模式:['(?P [ - \ w \ d] +),(?P \ d +)/ $']

I am attaching the link to the github repository for the project here, as I don't have any idea what went wrong please let me know where to look. git repository

我在这里附加到项目的github存储库的链接,因为我不知道出了什么问题,请让我知道在哪里看。 git存储库

1 个解决方案

#1


0  

I don't see why you have a comma in your pattern, did you mean to use a slash?

我不明白为什么你的模式中有逗号,你的意思是使用斜杠吗?

'^(?P<slug>[-\w\d]+),(?P<pk>\d+)/$'
#                   ^ ??

Also, the error indicates you're passing only the 'pk'. However, now that that pattern has been updated with a 'slug' parameter, you need to pass this also.

此外,错误表明您只通过'pk'。但是,现在该模式已使用'slug'参数更新,您还需要传递它。

#1


0  

I don't see why you have a comma in your pattern, did you mean to use a slash?

我不明白为什么你的模式中有逗号,你的意思是使用斜杠吗?

'^(?P<slug>[-\w\d]+),(?P<pk>\d+)/$'
#                   ^ ??

Also, the error indicates you're passing only the 'pk'. However, now that that pattern has been updated with a 'slug' parameter, you need to pass this also.

此外,错误表明您只通过'pk'。但是,现在该模式已使用'slug'参数更新,您还需要传递它。