Django serve static index.html with view at '/' url

后端 未结 5 2022
面向向阳花
面向向阳花 2020-12-25 11:14

I have my index.html in /static/ folder. My django app is running ok when i try:

http://127.0.0.1:8000/index.html

But i want to acces index

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 11:26

    You don't need to subclass TemplateView in this case. You can use TemplateView directly in your url conf, as long as index.html is in your templates directory.

    from django.views.generic.base import TemplateView
    
    urlpatterns = [
        url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"),
    ]
    

提交回复
热议问题