Django本地服务器显示模板未找到。

huangapple go评论57阅读模式
英文:

the django localhost server says template not found

问题

我创建了一个名为HelloWorld的Django项目,并创建了一个名为Pages的应用程序。我尝试使用以下结构中的HTML创建模板,但它不起作用。
相关的截图:

Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。

请帮助我,让我知道哪里出了问题。

英文:

I created a Django project named HelloWorld and created an app called Pages. I tried to make a template using HTML in the structure shown below . it does not work.
relevant screenshots:

Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。
Django本地服务器显示模板未找到。

please help and let me know what is wrong.

答案1

得分: 0

  1. 标准的Django结构应该是
helloworld
   helloworld
   pages
      templates
          pages
             home.html

以及视图:

class HomePageView(TemplateView):
    template_name = "pages/home.html"
  1. 如果你想将模板放在"global"文件夹中,那么根据BASE_DIR的情况,你可能需要将"templates"文件夹移动到上一级:
helloworld
   templates
   helloworld
   pages

你可以在settings.py中简单地打印BASE_DIR以确保它指向哪里:

settings.py

print(BASE_DIR)
英文:
  1. standard django structure would be
helloworld
   helloworld
   pages
      templates
          pages
             home.html

and view:

class HomePageView(TemplateView):
    template_name = "pages/home.html"

  1. if you want to keep the template in the "global" folder then depending on BASE_DIR most certainle you need to move the folder "templates" one level up:
helloworld
   templates
   helloworld
   pages

You can simply print BASE_DIR in settings.py to be sure where it
points to:

settings.py

print(BASE_DIR)

huangapple
  • 本文由 发表于 2023年7月18日 01:24:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定