简体   繁体   中英

How can i include my template from the static folder in django

I have the djnago app structure like

myproject/myapp

myproject/myapp/static/site/app/index.html

I want to include that template in my file like this

url(r'^public$', TemplateView.as_view(template_name="/static/site/app/index.html")),

but it says template not found

 import os
 import sys

 PORJECT_ROOT = os.path.join(os.path.dirname(__file__),'..')
 sys.path.insert(0, os.path.join(PROJECT_ROOT,'static'))

确保文件夹包含在TEMPLATE_DIRS设置中(位于settings.py中)。

Generally(by convention) template files folder is project_root_folder\\templates folder, update TEMPLATE_DIRS in settings.py:

import os
PORJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    os.path.join(PORJECT_ROOT, 'templates'),
)

While static store only javascript/css/images fiels.

That will make future develop and deploy easier.

BY default django checks in app/templates directory for a template match, or in the project_root/templates/. You should have the directory listed in the TEMPLATE_DIRS setting as others have stated.

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