how to use the href attribute in django templates
Suppose u are at
myapp/detail
and u want to go at page
myapp/anything
U shoud do this
<a href="../anything">Page</a>
Add /
at start in href
:
<a href="/appname/detail/{{ job.id }}/">{{ job.name }}</a>
And for the url
tag to work you need to do it like this:
<a href="{% url 'appname.views.detail' jobID=job.id %}">{{ job.name }}</a>
From my experience, as long as you have defined the url of the page the href
tag should lead to in urls.py
, include the absolute path in the format below.
Site name: yyyy.com
Url of page to redirect to in urls.py: yyyy.com/signup/
Sample link: <a href="/signup/">Signup</a>
You will notice that what goes inside the href tag is sort of appended to the current url. For more dynamic links, you can use some python as of DTL guidelines.