Mati
Mati

Reputation: 41

How to create two templates in django for the same applicaton?

Good afternoon community,

I am new to developing and I am working on a personal project in order to practice and get experience.

The URL path for my project is:

http://127.0.0.1:8000/simple_investing/

simple_investing is a static html template and I would like to add another template name concepts (http://127.0.0.1:8000/simple_investing/concepts).

The first part (simple_investing) works, but concepts does not.

Hereunder is my code:

simple_investing urls.py

urlpatterns = [
path('', TemplateView.as_view(template_name='simple_investing/main.htm')),
path('', TemplateView.as_view(template_name='simple_investing/concepts.htm')

mysite urls.py

path('simple_investing/', include('simple_investing.urls')),

I get the following error 404:

The current path, simple_investing/concepts, didn’t match any of these.

Any hints as to how can I solve this.

Upvotes: 1

Views: 252

Answers (2)

hhhameem
hhhameem

Reputation: 51

In Django, it checks every URL serially from the first. If any of the URL matches, it goes to that URL and doesn't care about the others.

So, as you are using both only (' ') after 'simple_investing/', the first (' ') will encounter and redirect you to that URL. In that case, the second(' ') will never encounter and that's why you are only seeing http://127.0.0.1:8000/simple_investing/

To get your desired result, follow the answer of @mkalioby

I hope I am clear to you why you aren't getting to see the second URL.

To know more about URL follow Official Document of URL

Upvotes: 0

Mohamed ElKalioby
Mohamed ElKalioby

Reputation: 2334

You are setting path of concepts to '', fix it as below

path('concepts/', TemplateView.as_view(template_name='simple_investing/concepts.htm')

Upvotes: 1

Related Questions