简体   繁体   English

适用于所有模板的Django Python base.html

[英]Django Python base.html for all templates

In my root directory i have a template and inside that template follow by a base.html that would be my main layout for my custom admin site. 在我的根目录中,我有一个模板,在该模板中,后面是base.html,这将是我自定义管理站点的主要布局。

in my templates/admin/base.html I have this code. 在我的templates / admin / base.html中,我有此代码。

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Layout Page</title>
</head>
<body>
    {% block content %}

    {% endblock %}
</body>
</html>

在此处输入图片说明

I want this base.html to be present in all my app templates. 我希望此base.html出现在我所有的应用模板中。

I have a app users in my mysite project that its the index.html page. 我的mysite项目中有一个应用程序用户,它的index.html页面。

在此处输入图片说明

inside my users/views. 在我的用户/视图中。

from django.shortcuts import render


def index(request):
    return render(request, 'users/index.html')

inside my templates/users/index.html I have this. 在我的template / users / index.html中,我有这个。

{% extends "admin/layout.html" %}

{% block content %}

    <h1>Hello World</h1>

{% endblock %}

I get an error that "TemplateDoesNotExist at /"

I come from a node.js background so I have no idea if if this is even a good practice. 我来自node.js,所以我不知道这是否是个好习惯。 I have came across many tutorials explaining the use of templates inside an app but non explaining outside the app. 我遇到过许多教程,它们解释了应用程序内模板的使用,但没有解释应用程序外的模板。

My understanding was that django bundle all templates into one. 我的理解是django将所有模板捆绑在一起。

Thanks in advance. 提前致谢。

I figure it out. 我知道了。 I need to add the global template my project settings. 我需要将全局模板添加到我的项目设置中。

'DIRS': [
        os.path.join(BASE_DIR, 'templates')
    ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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