Django Inclusion Tag SyntaxError

Trying to follow the Django Inclusion Tag documentation to create a custom template tag, but getting a template syntax error on line 6: def types(Information).

from django import template

register = template.Library()

def types(Information)
    informations = Information.objects.all()
    return {'informations': informations}

The file is within the /templatetags directory.

The model for Information:

class Information(models.Model):
    name = models.CharField(max_length=20)
    models = models.ManyToManyField('Model')

The template (edit.html):

{% load templatetag %}
   {% for information in informations %}
      <li> {{ information }} </li>
   {% endfor %}

Am I misunderstanding how to create the inclusion tag and objects? Thanks for any advice.


Well, not surprisingly, you have a syntax error. Function definitions, like anything that starts a block in Python, need to have a colon at the end:

def types(information):

Also note that for some reason you've named your argument Information, which will hide the class Information - whatever object you pass as the actual parameter will be used as the base for the objects.all() query, which is unlikely to work.

Need Your Help

Is Alphabet check in sql server?

sql sql-server sql-server-2008

How do I check whether a character is a valid Alphabet in sql-server ?