我想在home.html模板中顯示對象,該對象主要在laglist模板中。我用include標籤來執行操作,但它不起作用。下面是我的代碼:無法使用包含標籤的模板在Django中加載對象
laglist.html
{% extends "base.html" %}
{% block lag %}
<h2>Lam </h2>
{% for leggo in leggos %}
<p><a href= "{% url halldetail leggo.id %}" >{{ leggo.name }}</a><p>
<img src="{{MEDIA_URL}}/{{leggo.thumbnail_1.url}}" width="83" height="78"> <img src="{{MEDIA_URL}}/{{leggo.thumbnail_2.url}}" width="83" height="78" />
<li>{{ leggo.state }}</li>
{% endfor %}
{% endblock %}
信息查看laglist:
def lag_view(request):
leggos=Fin.objects.filter(state='venu')
for leggo in leggos:
print leggo.id
return render_to_response('laglist.html', {'leggos':leggos,'leggo':leggo,'Fin':Fin},context_instance=RequestContext(request))
home.html的
{% extends "base.html" %}
{% block content %}
<p> {% include 'laglist.html' %} </p>
{% endblock %}
查看產品
def homp(request):
return render_to_response('home.html',context_instance=RequestContext(request))
你laglist.html和home.html的都來自base.html文件延伸。很可能,當你包含這樣的模板時,這不起作用。 – Rohan