Issue
I am new in python programming and I created a project for learning. I have created three html pages when I click on the other page link it's show error page not found because url show previous page link with current page link (I don't know how to explain my problem)
For Example
I have two page index, home
if I am on index page(url for index page is "http://127.0.0.1:8000/index/") and want to go to the home page when I click on home page link its show an error because the url for home page is "http://127.0.0.1:8000/index/home/" and I want home page url like this "http://127.0.0.1:8000/home/". Same thing happen when I want to go from home page to index page but when I write manually, page open correctly
My code
reference code for index.html and home.html links
<a class="collapse-item" href="home">Home Page</a>
<a class="collapse-item" href="index">Index Page</a>
view.py
from django.shortcuts import render
from django.http import HttpResponse
def index_view(request):
return render(request, "index.html")
def home_view(request):
return render(request, "home.html")
app/urls.py
from django.urls import path
from . import views
urlpatterns= [
path('index/', views.index_view),
path('home/', views.home_view),
project/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("app.urls")),
]
Solution
You need to make changes in 'app/urls.py' and 'href' attributes. In django, every URL should be accessed with name.
Answered By - B.Anup
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.