我正在尝试在基本 html 页面内呈现模板。基本 html 具有整个站点通用的页眉、页脚、菜单。页面的中间部分必须来自子页面。我认为我一切都正确,200 OK,但是它不起作用,我看不到子页面、表单和div的内容。我只看到所有请求的 base.html 。我缺少什么?
project
|
---templates/base.html
---templates/childpage.html
base.html
{% load static %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="{% static 'css/custom.css' %}">
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
childpage.html
{% extends "base.html" %}
{% block content %}
<form action="" method="">
</form>
<br><br><br>
<div class="something">
<a>some content</a>
</div>
{% endblock content %}
观看次数
def home(request):
return render(request, 'base.html')
def askforchild(request):
return render(request, 'childpage.html')
网址
urlpatterns = [
url(r'^admin/', admin.site.urls),
url('', views.home, name='Site Home Page'),
url('askforchild', views.askforchild, name='child page'),
]
最佳答案
主页 ""
的 url 列表必须移至 url 列表的底部。正则表达式正在捕获所有请求作为主页请求。总而言之,URL 列表的底部应该有一个空模式。
关于python - 在 Python Django 中渲染基本 html 模板内的子页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59476576/