Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django inclusion_tag

I'm trying to create inclusion tag and place it on the page but it's not work.

My 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 debug page says that "Invalid block tag: 'weather'" so I guess I put declaration of inclusion_tag in wrong place? Where I need to put it to get it work?

like image 891
quux Avatar asked Aug 24 '12 21:08

quux


1 Answers

Template tags need to go in a module in your app's templatetags directory. See the code layout section of the custom template tag docs for full details.

You then have to load your tag library in the template before you use your tag.

{% load my_tags %}
{% weather %}
like image 181
Alasdair Avatar answered Sep 19 '22 18:09

Alasdair