How to get the url path of a view function in django

后端 未结 7 1303
醉话见心
醉话见心 2021-02-05 06:41

As an example:

view.py

def view1( request ):
    return HttpResponse( \"just a test...\" )

urls.py

urlpatterns = patter         


        
7条回答
  •  攒了一身酷
    2021-02-05 07:12

    This depends whether you want to get it, if you want to get the url in a view(python code) you can use the reverse function(documentation):

    reverse('admin:app_list', kwargs={'app_label': 'auth'})
    

    And if want to use it in a template then you can use the url tag (documentation):

    {% url 'path.to.some_view' v1 v2 %}
    

提交回复
热议问题