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

You need reverse.

from django.urls import reverse

reverse('app1.view.view1')

If you want to find out URL and redirect to it, use redirect

from django.urls import redirect 

redirect('app1.view.view1')

If want to go further and not to hardcode your view names either, you can name your URL patterns and use these names instead.

Leave a Comment

File not found.