Skip to Content
Django 3 Web Development Cookbook - Fourth Edition
book

Django 3 Web Development Cookbook - Fourth Edition

by Aidas Bendoraitis, Jake Kronika
March 2020
Intermediate to advanced
608 pages
17h 17m
English
Packt Publishing
Content preview from Django 3 Web Development Cookbook - Fourth Edition

How it works...

This filter used in a template, as shown in the following code, will render something similar to yesterday, last week, or 5 months ago:

{% load utility_tags %}{{ object.published|date_since }}

You can apply this filter to values of the date and datetime types.

Each template-tag library has a register of template.Library type where filters and tags are collected. Django filters are functions registered by the @register.filter decorator. In this case, we pass the is_safe=True parameter to indicate that our filter will not introduce any unsafe HTML markup.

By default, the filter in the template system will be named the same as the function or another callable object. If you want, you can set a different name for the filter by ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Django 2 Web Development Cookbook - Third Edition

Django 2 Web Development Cookbook - Third Edition

Jake Kronika, Aidas Bendoraitis

Publisher Resources

ISBN: 9781838987428Supplemental Content