Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Doesnotexist hints on how to implement

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to achieve the doesnotexist hint, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

Django runtime error, prompted TemplateDoesNotExist, a html file does not exist, of course, my html templates are all placed in the Templates directory, through the error message can be seen, django is directly to me to the template path as an absolute path, naturally can not find the html file. After looking at the project setting file, I see the setting method of Template, including an option of 'DIRS'. After Baidu, I know that the path of the directory where the project template is located needs to be added here.

TemplateDoesNotExist Code:

'DIRS': [os.path.join (BASE_DIR,'myapp/Templates')]

Where BASE_DIR refers to the directory where the db.sqlite3 of the project is located, followed by the path of the template directory relative to db.sqlite3.

The DIRS under TEMPLATES needs to be set in the settings.py file as follows: TEMPLATES= [

{

'BACKEND':'django.template.backends.django.DjangoTemplates'

'DIRS': [

'/ home/html/example.com'

'/ home/html/default'

]

}

{

'BACKEND':'django.template.backends.jinja2.Jinja2'

'DIRS': [

'/ home/html/jinja2'

]

}

]

Where DIRS is the path of the html template file

Prompt TemplateDoesNotExist? in Django.

In the learning process of using Django to build a simple blog, I encountered the problem of TemplateDoesNotExist when I opened the browser to enter the test page after running pythonmanage,pyrunserver on the terminal. It probably means that the TEMPLATE_DIRS I used in setting.py was discarded after Django1.8. Let me put the template path into the TEMPLATE exclusive directory. I think that's what he meant.

Thank you for reading this article carefully. I hope the article "doesnotexist Tips how to achieve" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report