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?
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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With