简体   繁体   中英

Django , how to extend from template in main static folder

I have folder called mytemplates for sites base templates

Project ----App1,App2,App3,static

Now in my static folder i have folder called mytemplates/temp1/index.html

Now in my app1

app1/templates/app1/index.html

I want to do this

{% extends "/static/mytemplates/temp1/index.html" %}

But its saying that template not found

You don't need to write /static .

You must have your /static folder defined in settings.TEMPLATE_DIRS otherwise django's template loader will never search there. You must write out the full path, not the relative path.

By default, template loaders search inside of the template folder, so they don't depend on which template folder they are in. Meaning, writing {% extends "mytemplates/temp1/index.html" %} will result in django making a list of all your template dirs, appending mytemplates/temp1/index.html to the absolute path of each, and determining whether or not the concatenated path exists. If it doesn't, it keeps trying your other template directories. If after trying all your directories no match is found, django raises an exception.

Writing simply {% extends "mytemplates/temp1/index.html" %} will work assuming your static folder is in your settings.TEMPLATES_DIR tuple and that "mytemplates/temp1/index.html" exists in static .

You don't put a full pathname to the file in, look here for the exact syntax. If's the same name that you would call your template from your view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM