【发布时间】:2017-07-16 07:16:21
【问题描述】:
我无法将一个 html 文档 (child - base_home.html) 扩展到另一个父 html 文档 - base.html 我有下一个 Django 项目结构:
Testdjango/
blog/
migrations/
templates/
blog/
base.html
base_home.html
__init.py__
admin.py
apps.py
models.py
tests.py
urls.py
views.py
db.sqlite3
manage.py
我的父模板是一个base.html,代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>{% block title %}{% endblock %} – Blog</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/journal/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template
<link href="starter-template.css" rel="stylesheet"> -->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Blog</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
{% block content %}
{% endblock %}
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
我的“孩子”base_home.html 有下一个代码:
{% extends "blog/base.html" %}
{% block title %}
Home
{% endblock %}
{% block content %}
Lorem bla bla
{% endblock %}
在页面中我看不到 base_home.html 中的任何内容
【问题讨论】:
-
如果你渲染
base_home.html,你看到网页pgae上渲染的html内容了吗? -
请展示你的观点。
-
我的看法:
from django.http import HttpResponse, request from django.shortcuts import render # Create youcoding=utf-8r views here. def home(request): return render(request, 'blog/base.html') -
@karthikr,不,从 base_home.html 看不到任何东西
-
你能粘贴扩展错误的堆栈跟踪吗?到时候调试会很容易。我的猜测是,您没有在 settings.py 中正确给出 template_dirs 路径。
标签: python django django-forms django-templates django-admin