[Answered ]-Django: how to make a link on main page to sub-pages

0👍

It looks like you’re trying to pass template name to url template tag. What you should actually do is to define url name in your urls.py, so it would look similiar to this:

url(r'^page1/$', YourView.as_view(), name="page1")

and then in template:

<a href="{% url "page1" %}">Page 1</a>

You should rather avoid hardcoding urls doing something like this:

<a href="/page1">Page 1</a>

because when in future you’d like to change the url you’ll have to do it in two places: in urls.py and in template(s), while when using {% url %} template urls.py will be the only place to do it.

2👍

I advice you first read this link for understanding django url structure
https://docs.djangoproject.com/en/1.10/topics/http/urls/#url-namespaces

The Solution will be like that:

<h3>This is the URL for "page1": <a href="/page1"> Click here</a></h3>

<h3>This is the URL for "page2": <a href="/page2"> Click here</a></h3>

and you must define this urls in urls.py

Leave a comment