calling index.html

11 views
Skip to first unread message

Tato Müller

unread,
Sep 28, 2019, 6:26:45 PM9/28/19
to Django users
Hi everyone.

How can i call an html page when i request the root of my app, like http://127.0.0.1:8000/app.
I want index.html loads when i call this url.

Could you help me?

Lim Kai Wey

unread,
Sep 29, 2019, 12:44:04 AM9/29/19
to django...@googlegroups.com
Greetings Müller,

In order for your template to load for that specific page, you have to state it under that page’s view in views.py

Eg:
class IndexView():
       template_name = “index.html”

// Or if it’s a function view

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

Hope it helps!

Sincerely,
Kai Wey

Lim Kai Wey

unread,
Sep 29, 2019, 12:50:55 AM9/29/19
to django...@googlegroups.com
Note: Nonetheless, you should read more about the documentation or the tutorials available since everything you need to start you first Django project is already there.

אורי

unread,
Sep 29, 2019, 4:45:16 AM9/29/19
to django...@googlegroups.com
You can use generic.TemplateView to load an HTML template.

See for example:
 
Although, there are many options to use in your templates and usually it's better not to load a static HTML page.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d7441b68-9cf2-47ec-950e-b44b6bd9717c%40googlegroups.com.

RAJ musixx

unread,
Sep 29, 2019, 8:23:11 AM9/29/19
to django...@googlegroups.com
1.GO to views.py and the index function 
2.def index(request):
       return render(request, 'index.html')
3.goto ur urls.py and write following

path(' ', name of your view.index, name = 'home' )

THis how u can render any page to browser as ur home page .
you need to import render in ur views file ...... check google how to import render.

Deepak

unread,
Sep 29, 2019, 8:23:16 AM9/29/19
to django...@googlegroups.com
Basically bro,when you you serve project it takes the index file,You can change route from / to /app then you will be directed there.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d7441b68-9cf2-47ec-950e-b44b6bd9717c%40googlegroups.com.


--
Thanks
Deepak Paliwal
Mob 8619437133
Reply all
Reply to author
Forward
0 new messages