0

我能够渲染它home.html 并打印出来Mary had a little lambsitetitle

这是代码home.html

<head>
</head>
<body>
<h1>{{sitetitle}}</h1>
<h1>{% block fun %} {% endblock %}</h1>
</body> 

但它不会在 中渲染funtitle.html,尽管它位于同一目录中。

这是代码title.html

{% extends "home.html" %}
{% block fun %}
{{ link }}
{% endblock %}

这是views.py from django.shortcuts import render from models import siteprop from django.template import loader的代码

def testf(request) :
 obj=siteprop.objects.first()
 context=obj.__dict__
 if '_state' in context: 
 del context['_state']
 print context
 return render(request,"home.html",context)

这是代码urls.py

from django.conf.urls import include, url
from django.contrib import admin
from thingslab import views
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^test/',views.testf,),
]
4

1 回答 1

3

中的funtitle.html未渲染,因为在您的视图中您正在渲染home.html.

Django 不会因为它还包含一个块而自动知道title.html应该包含的代码。home.htmlfun

您必须渲染title.html而不是home.html

 return render(request, "title.html", context)
于 2015-08-20T05:53:12.213 回答