问答详情
源自:4-5 实现文章详情页面的跳转

404报错,找不到路径:http://127.0.0.1:8000/play/detail/1

  1. ^ play / ^ detail / <int:article_id> $



提问者:宝慕林4373242 2019-12-20 11:07

个回答

  • 勇往直前3
    2021-02-01 10:07:41

    django 3.1.5 这样写
    path('detail/<int:article_id>/', blog.views.get_detail),
    参考https://docs.djangoproject.com/


  • niuxiaoying
    2020-01-10 11:08:27

    应该是版本不一样所以路由配置不一样把,你改改这个试试:
    http://img3.mukewang.com/5e17e9ff000189cd06560050.jpg

    就是把老师讲的那个<int:article_id>改成

    (?P<article_id>[0-9]+)

    具体和上图那样子。

    然后在views.py里面稍微改一下

    http://img1.mukewang.com/5e17ea7e0001e6ac05800370.jpg

    只有第41行的代码不一样,注意改一下,然后应该就可以了

  • niuxiaoying
    2020-01-10 10:09:13

    我也是这个错误

  • 宝慕林4373242
    2019-12-20 11:15:48

    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
                      })


  • 宝慕林4373242
    2019-12-20 11:11:59

    Page not found (404)

    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:

    1. ^play/ ^hello/$

    2. ^play/ ^content/$

    3. ^play/ ^index/$

    4. ^play/ ^detail/<int:article_id>$

    5. ^admin/

    The current path, play/detail/1, didn't match any of these.