Is there a way of grabbing a subset of the URL in Django views.py?
I have tried request.build_absolute_uri()
but that captures slightly more than I want.
E.G. If the URL was http://127.0.0.1:8000/jobs/new
I would like to get http://127.0.0.1:8000/
Instead I end up getting the entire URL, with the page names.
I am wondering if there is a rootURL function in Django or something similar maybe?
This question has a few approaches which are:
Using request.get_host(),
<a href="http://{{ request.get_host() }}">Go back home</a>
Using href='/',
<a href="/">Go back home</a>
Or Using the root url defined in your url conf.
url(r'^mah_root/$', 'someapp.views.mah_view', name='mah_view'),
Then in your template:
<a href="{% url mah_view %}">Go back home</a>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments