david
david

Reputation: 6805

Where are the built in django template tags located?

I found a directory called template tags in the django repo, but I do not see the template tags I'm looking for. Specifically, this one:

{{ testdate | date:'m-d-Y, H:i a' }}

Upvotes: 1

Views: 82

Answers (1)

at14
at14

Reputation: 1204

The source code you are looking for,

@register.filter(expects_localtime=True, is_safe=False)
def date(value, arg=None):
    """Format a date according to the given format."""
    if value in (None, ''):
        return ''
    try:
        return formats.date_format(value, arg)
    except AttributeError:
        try:
            return format(value, arg)
        except AttributeError:
            return ''

You can find them in the defaultfilters.py file.

django -> django -> template -> defaultfilters.py

https://github.com/django/django/blob/ff05de760cc4ef4c7f188e163c722ec3bc1f0cbf/django/template/defaultfilters.py#L687

Upvotes: 3

Related Questions