簡體   English   中英

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

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

我的模板名為 hello.html

<h1>Hello World</h1>

我的意見.py

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

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

此外,如果我嘗試 return HttpResponse('Hello World') 它正在工作。 但是蘭德不起作用。

確保您在如下設置中指定了templates

   

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

並確保您在設置的INSTALLED_APPS中也提到了您的應用程序,並將所有 html 文件保存在模板文件夾中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM