I want to have the external html read into the html in the template of Django.

Asked 2 years ago, Updated 2 years ago, 80 views

I am trying to incorporate the django application into a web site that is mostly static html.
The directory configuration is as follows:

root/
 ├ var/
 │  /wwwwwwwwwwwwwwwww.
 │   h html/
 │       st static
 │       │ st style.css
 │       │ bbase.js
 │       │ 
 │       wweb/
 │          hhead.html
 │          f footer.html
 │          b base.html
 │
 └ opt/
   └ django /
     ├ project/
     │
     ├ apps/
     ├ ├ views.py
       ├ template/
            ├ index.html

I'd like django's /opt/django/template/index.html to load html under /var/www/html/web/, but I don't know how to include it.
I was wondering if I could use {%include"/var/www/html/web/head.html"%}, but I couldn't.

Static html reads css and js, so I don't want to ruin the directory configuration.
If there is any good way, please let me know.

python django

2022-09-30 17:40

1 Answers

It's solved.
Edit TEMPLATES in setting.py as follows:

TEMPLATES=[
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'apps/template'), '/var/wwww/html/web/']
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

This allows
{%include"head.html"%}.


2022-09-30 17:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.