Get the App
SLTechnology News&Howtos  ›  Development  › 

Doesnotexist hints on how to implement

Shulou Source: shulou.com Published: 2022-06-03 11:01:53 09月12日 Update

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!

Tags: Templates paths files directories tips articles projects learning that is meaning location run code value interests including blogs at the same time that is methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Microsoft MariaDB Shulou Tech Info