python django giant pit templates template django.template.exceptions.TemplateDoesNotExist

Recently, I am learning django by myself. When I got to the templates configuration to display static files, I have been stuck here and reported an error. I obviously copied others and said that I couldn’t find the template.

Record my solution: [Because everyone is basically using the code for beginners, so basically there will be no problems in other places. The dimension below may be a little different from the video]

Find the setting file and carefully observe the template file path of your templates. At this time, you can output BASE_DIR, which can be viewed in the console below. Pay attention to mine, only F:\python_project\django\firstproject is output, but there is still a layer of firstproject on the right side of me!! So I can’t find templates here

 Therefore, the following pictures are stitched together. You can't just write a templates but should write the path I lack as 'firstproject/templates' instead of 'templates'. At this time, you can also output it directly and observe the alignment with the left directory templates. No.

print(os.path.join(BASE_DIR,'firstproject/templates'))

 

Guess you like

Origin blog.csdn.net/qq_43644046/article/details/130482273