我试图创建包含标签,并将其放在页面上,但这是不工作的。
我的views.py:
from django.shortcuts import render_to_response, redirect
from django import template
register = template.Library()
@register.inclusion_tag('weather.html')
def weather():
return {'city': 'angola'}
def home(request):
return render_to_response('index.html')index.html
<title> TITLE </title>
Hi everyone!
{% weather %}weather.html
weather is fine in {{city}}Django调试页面显示“无效块标记:‘天气’”,所以我猜我把inclusion_tag声明放错了地方?我需要把它放在哪里才能让它工作?
发布于 2012-08-25 05:35:47
模板标签需要放在应用程序的templatetags目录中的一个模块中。有关完整的详细信息,请参阅自定义template tag docs的代码布局部分。
然后,您必须在使用标记之前在模板中load您的标记库。
{% load my_tags %}
{% weather %}https://stackoverflow.com/questions/12116664
复制相似问题