[Django]-Django reference url in views.py

7👍

You’ll want to use reverse().

from django.core.urlresolvers import reverse

class ExampleView(TemplateView):
    some_var = reverse('example2')
    print some_var

EDIT:

If you want the absolute uri, you can build it with build_absolute_uri

from django.core.urlresolvers import reverse

class ExampleView(TemplateView):
    some_var = request.build_absolute_uri(reverse('example2'))
    print some_var
👤Alex

0👍

You might look at urlresolvers. But it will give only URI , you will have to manually add “http://localenv.com…”.

👤DAKZH

Leave a comment