Django - How to pass several arguments to the url template tag

后端 未结 3 683
陌清茗
陌清茗 2021-02-12 11:36

In my urls.py I have:

(r\'^(?P\\d{4})/(?P\\d{2})/(?P\\d{2})/section/(?P[-\\w]+)/$\', 
    \'paper.views.issue_sec         


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-12 11:49

    I had the same issue (I'm using Django 1.3.1) and tried Gregor Müllegger's suggestion, but that didn't work for two reasons:

    • there should be no commas between year, month and day values
    • my class-based generic view seems to take only keyword arguments

    Thus the only working solution was:

    {% url news_detail slug=object.slug year=object.date|date:"Y" month=object.date|date:"m" day=object.date|date:"d" %}
    

提交回复
热议问题