[Django]-How to place links in django templates

5πŸ‘

βœ…

The first problem is that both the path to the views.index and views.terms share the same path. As a result, you have made views.terms inaccessible.

You thus should change one of the paths, for example:

from django.urls import path   
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('terms/', views.terms, name='terms')
]

You better use the {% url ... %} template tag [Django-doc] to resolve the URLs, since if you later decide to change the path of a certain view, you can still calculate the path.

In your template, you thus write:

By signing in, you agree to our <a href="{% url 'terms' %}">Terms Of Use Policy</a>

1πŸ‘

urlpatterns = [
    path('', views.index, name="index"),
    path('terms/', views.terms, name="terms")
]
By signing in, you agree to our <a href="{% url 'terms' %}">Terms Of Use Policy</a>
or
πŸ‘€arjun

Leave a comment