how to create custom tags in django?
Share
how to create custom tags in django?
The first thing you can learn HTML, whether you want to become a professional web developer or just want to learn more about how websites work. The basic language for developing web pages and web applications is HTML. A server ...
Asynchronous Javascript One of AJAX’s benefits is it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server. However, using AJAX does not guarantee the user will not wait for the asynchronous JavaScript and ...
How To Make Cookie Free Domain An HTTP cookie (also known as a web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the user’s computer by the ...
Create a file like file_name.py in any app and place this below code
#Code
from django import template
register = template.Library()
IN TEMPLATE FILE
@register.simple_tag <———————————————— Regestring a tag
def get_otp_sec(token): <———————————————— Function or tag name
user = models.users.objects.get(token=token,end_date__isnull=True);
diff = datetime.now() – user.otp_created_at;
return diff.total_seconds();<—————————————— Calculating Seconds betweend two dates
IN HTML FILE
{% random_quote token_value as rand%}
To DISPLAY THE VALUE
{{ rand }}