简体   繁体   English

我无法在 django 中使用渲染查看我的模板

[英]I can't view my template with render in django

My template with called hello.html我的模板名为 hello.html

<h1>Hello World</h1>

My views.py我的意见.py

   from django.shortcuts import render
   from django.http import HttpResponse

   def say_hello(request):
       return render(request,'hello.html')

Also if i try return HttpResponse('Hello World') it is working.此外,如果我尝试 return HttpResponse('Hello World') 它正在工作。 But rander is not working.但是兰德不起作用。

Make sure you have specifed templates in settings like below确保您在如下设置中指定了templates

   

     TEMPLATES = [
            {
                "BACKEND": "django.template.backends.django.DjangoTemplates",
                "DIRS": [BASE_DIR / 'templates'],
                "APP_DIRS": True,

and make sure you have all also mentioned your app in INSTALLED_APPS in settings, and also keep you all html files in templates folder并确保您在设置的INSTALLED_APPS中也提到了您的应用程序,并将所有 html 文件保存在模板文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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