^ play / ^ detail / <int:article_id> $
django 3.1.5 这样写 path('detail/<int:article_id>/', blog.views.get_detail),
参考https://docs.djangoproject.com/
应该是版本不一样所以路由配置不一样把,你改改这个试试:
就是把老师讲的那个<int:article_id>改成
(?P<article_id>[0-9]+)
具体和上图那样子。
然后在views.py里面稍微改一下
只有第41行的代码不一样,注意改一下,然后应该就可以了
我也是这个错误
url(r'^detail/<int:article_id>$',views.get_detail_page) def get_detail_page(request,article_id): all_article = Article.objects.all() curr_article = None for article in all_article: if article.article_id == article_id: curr_article = article break #curr_article = Article.objects.all()[1] session_list = curr_article.content.split('\n') return render(request,'cs/detail.html', { 'curr_article': curr_article, 'session_list':session_list })
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/play/detail/1 |
Using the URLconf defined in project.urls
, Django tried these URL patterns, in this order:
^play/ ^hello/$
^play/ ^content/$
^play/ ^index/$
^play/ ^detail/<int:article_id>$
^admin/
The current path, play/detail/1
, didn't match any of these.