V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
projectpython
V2EX  ›  问与答

djiango 2.0.3 url 配置问题

  •  
  •   projectpython · Oct 20, 2018 · 1374 views
    This topic created in 2751 days ago, the information mentioned may be changed or developed.
    报错:Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['home\\/detail\\/\\<int\\:topic\\.id\\>$']
    我的路由:path('detail/<int:topic.id>',views.topic,name='detail')
    views:
    def topics(requset):
    topics = Topic.objects.order_by('date_added')
    context = {'topics':topics}
    return render(requset,'blog_home/topics.html',context)
    模板中:<ul>
    {% for topic in topics %}

    <li>
    <a href="{% url 'detail' topic.id %}">{{ topic }}</a>
    </li>
    {% empty %}a
    <p>no have topic yet.</p>
    {% endfor %}

    </ul>
    views 中函数 topics 传到模板中的字典有 2 个值,新手一直找不到原因求大神解救!
    ifoolish
        1
    ifoolish  
       Oct 20, 2018
    加上你的 appname 试试?比如 {% url 'appname:detail' topic.id %}
    projectpython
        2
    projectpython  
    OP
       Oct 20, 2018
    加了 不是命名空间的问题 依然报 Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['home\\/detail\\/\\<int\\:topic\\.id\\>$']
    projectpython
        3
    projectpython  
    OP
       Oct 20, 2018
    人也太少了,问题解决了把路由改为 re_path('^detail/(?P<topic_id>[0-9]+)/$',views.topic,name='detail')就 ok 了 但是依然不知道问题出在那?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2471 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:19 · PVG 17:19 · LAX 02:19 · JFK 05:19
    ♥ Do have faith in what you're doing.