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

后端 未结 7 1314
醉话见心
醉话见心 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:20

    Universal approach

    1. install Django extensions and add it to INSTALLED_APPS

    2. Generate a text file with all URLs with corresponding view functions

    ./manage.py show_urls --format pretty-json --settings= > urls.txt

    like

    ./manage.py show_urls --format pretty-json --settings=settings2.testing > urls.txt

    1. Look for your URL in the output file urls.txt
        {
            "url": "/v3/blockdocuments//",
            "module": "api.views.ganeditor.BlockDocumentViewSet",
            "name": "block-documents-detail",
        },
    

提交回复
热议问题