Ali Barani
Ali Barani

Reputation: 276

How to navigate from current html page to another html page in django

I'm working on django app and i'm facing a problem when i need to navigate from my index.html page to another about.html page. I'm setting everything in this way below:

urls.py (myproject)

from django.urls import path, include
urlpatterns = [
    path('', include('weather_app.urls')),
    path('about/', include('weather_app.urls'))
]

urls.py (myapp)

from django.urls import path
from . import views

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

In index.html, everything is working well, so i will not put the code.

and in view.py:

from django.shortcuts import render
import requests

def about(request):
   return render(request, "about.html")

i have the code below in my index.html:

<a href="/about.html/">About </a> 

and i cannot get about.html page when click About link as you can see above.

Can anybody help me?

Thanks in advance..

Upvotes: 2

Views: 7173

Answers (1)

Cheche
Cheche

Reputation: 1516

You have to use this tag to avoid manual rendering of urls. In your code:

<a href="{% url 'about' %}">About </a>

Let me know if this works!

Upvotes: 5

Related Questions