简体   繁体   中英

how can i create a html file template in django application?

我正在学习 Django,我有一个问题,在互联网上没有答案,这就是问题所在,我创建了一个文件夹作为“应用程序”,我在应用程序中创建了另一个文件夹作为“挑战”(在 VS Code 中Django 应用程序),所以我们现在有 2 个嵌套文件夹我想创建一个 HTML 页面,并创建一个文件为“index.html”,但 VS Code 无法将此文件视为 HTML 文件

You need to make a folder structure like this

>app_name
>>...
>>templates
>>>app_name
>>>>index.html

views.py

from django.shortcuts import render

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

urls.py

from . import views

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM