Tuesday, April 22, 2025

Django Dynamic Navigation

This is our navigation file: 


<a href="{% url 'home' %}">Home</a> | <a href="{% url 'about' %}">About</a> | <a href="{% url 'contact' %}">Contact</a> |

The {% url %} template tag in Django is used to generate URLs for views.

This is useful because it allows you to easily create links to views without having to hard-code the URLs in your templates. If you need to change the URL for a view, you can simply update the URL pattern in the urls.py file, and all the links generated with {% url %} will automatically update to reflect the new URL.

After applied changes and server rerun we can access those links. This is what you will se in terminal where server is running: 


[26/Jul/2020 14:51:58] "GET / HTTP/1.1" 200 102
[26/Jul/2020 14:51:58] "GET / HTTP/1.1" 200 102
[26/Jul/2020 14:51:59] "GET /about/ HTTP/1.1" 200 104
[26/Jul/2020 14:51:59] "GET /about/ HTTP/1.1" 200 104
[26/Jul/2020 14:52:00] "GET /about/ HTTP/1.1" 200 104
[26/Jul/2020 14:52:00] "GET /about/ HTTP/1.1" 200 104
[26/Jul/2020 14:52:02] "GET /contact/ HTTP/1.1" 200 106
[26/Jul/2020 14:52:02] "GET /contact/ HTTP/1.1" 200 106
[26/Jul/2020 14:52:03] "GET /contact/ HTTP/1.1" 200 106
[26/Jul/2020 14:52:03] "GET /contact/ HTTP/1.1" 200 106
[26/Jul/2020 14:52:03] "GET /contact/ HTTP/1.1" 200 106
[26/Jul/2020 14:52:04] "GET / HTTP/1.1" 200 102
[26/Jul/2020 14:52:04] "GET / HTTP/1.1" 200 102

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...