英文:
the django localhost server says template not found
问题
我创建了一个名为HelloWorld的Django项目,并创建了一个名为Pages的应用程序。我尝试使用以下结构中的HTML创建模板,但它不起作用。
相关的截图:
请帮助我,让我知道哪里出了问题。
英文:
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:
please help and let me know what is wrong.
答案1
得分: 0
- 标准的Django结构应该是
helloworld
helloworld
pages
templates
pages
home.html
以及视图:
class HomePageView(TemplateView):
template_name = "pages/home.html"
- 如果你想将模板放在"global"文件夹中,那么根据BASE_DIR的情况,你可能需要将"templates"文件夹移动到上一级:
helloworld
templates
helloworld
pages
你可以在settings.py中简单地打印BASE_DIR以确保它指向哪里:
settings.py
print(BASE_DIR)
英文:
- standard django structure would be
helloworld
helloworld
pages
templates
pages
home.html
and view:
class HomePageView(TemplateView):
template_name = "pages/home.html"
- 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论