1

I was trying to call one html file from another via Django. I actually have no errors inside my project(It works). But when I am trying to call the second html file the page refreshes only. Here is my code, thanks:D. My projects name is information and the name of my app is basic.

basic.views.py:

from django.shortcuts import render
# Create your views here.



def index(request):
    return render(request,'basic/index.html')


def customer(request):
    return render(request,'basic/customer.html')

basic.urls.py:

from django.urls import path
from basic import views


app_name='basic'

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

information.urls.py:

from django.contrib import admin
from django.urls import path,include
from basic import views


urlpatterns = [
    path('',views.index,name="index"),
    path('admin/', admin.site.urls),
    path('',include('basic.urls'))
]
2
  • you have same url string in base.urls.py, isn't that weird ? Commented May 20, 2020 at 20:26
  • The two pants are the same, so it will always take the first one. Commented May 20, 2020 at 20:29

1 Answer 1

1

The problem is that you have two paths that match exactly the same path. So that means each time you make a request with an empty path, the first one is used.

You should make use of non-overlapping paths, for example:

# basic/urls.py

from django.urls import path
from basic import views


app_name='basic'

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

and in your information/urls.py:

# information/urls.py

from django.contrib import admin
from django.urls import path,include
from basic import views

urlpatterns = [
    path('', views.index, name='index'),
    path('admin/', admin.site.urls),
    path('basic/', include('basic.urls'))
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.