Using {% url ??? %} in django templates

后端 未结 6 2343
囚心锁ツ
囚心锁ツ 2020-12-07 13:02

I have looked a lot on google for answers of how to use the \'url\' tag in templates only to find many responses saying \'You just insert it into your template and point it

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 13:48

    The selected answer is out of date and no others worked for me (Django 1.6 and [apparantly] no registered namespace.)

    For Django 1.5 and later (from the docs)

    Warning Don’t forget to put quotes around the function path or pattern name!

    With a named URL you could do:

    (r'^login/', login_view, name='login'),
    ...
    logout
    

    Just as easy if the view takes another parameter

    def login(request, extra_param):
    ...
    login
    

提交回复
热议问题