###1つのアプリケーション内にあるbase.htmlを別のアプリケーションから継承したいです。
project ├── base │ ├── templates │ │ └── base.html │ ├── urls.py │ └── views.py ├── app1 │ ├── templates │ │ └── app1 │ │ └── index.html │ ├── urls.py │ └── views.py ├── app2 │ ├── templates │ │ └── app2 │ │ └── index.html │ ├── urls.py │ └── views.py . . . └── another-app ├── templates │ └── another-app │ └── index.html ├── urls.py └── views.py
かなり省略はしてますが、上記のように一つのapplication(base)に共通で使用する
base.htmlを置いて、他のapplicationから継承して使用したいと考えてます。
###エラーの内容
TemplateDoesNotExist at /base
###base/templates/base.html
html
1{% load staticfiles %} 2<!DOCTYPE html> 3<html lang="{{ LANGUAGE_CODE|default:'ja' }}"> 4<head></head> 5<body> 6 7{% block content %} 8 {{ content }} 9{% endblock %} 10 11</body> 12<html>
###another-app/templates/another-app/index.html
html
1{% extends "base/base.html" %} 2 3{% load staticfiles %} 4 5{% block content %} 6 7 // 省略 8 9{% endblock content %}
###base/urls.py
python
1from django.conf.urls import url 2from enduser import views 3 4urlpatterns = [ 5 url(r'^base', views.index), 6]
###base/views.py
python
1from django.shortcuts import render 2 3def index(request): 4 return render(request, 'base/base.html')
###同一アプリケーションにbase.htmlを置くとうまく継承されることは確認できました。
another-app/templates/base.html
にbase.htmlを置いて
another-app/templates/another-app/index.html
で継承をしていた部分を
{% extends "base.html" %}
に変更するとうまく継承できていることは確認できました。
###バージョン
Django 1.10.6
前提で、そもそもapplicationごとにtemplatesを置いて管理すること自体がベストプラクティスではないのでしょうか。
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。