In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to analyze how to write custom template tags tags and filters in Django, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Django template system comes with a series of built-in tags and filters, generally can meet your requirements, if you feel the need for more accurate template tags or filters, you can write your own template tags and filters, and then use the {% load%} tag to use them.
Code layout
Custom tags and filters must depend on a django app, that is, custom tags and filters are bound to app. The app should contain a templatetags directory, which is at the same level as model.py,views.py. Remember to create a _ _ init__.py file in this directory and django knows that this is a python package. In this directory, you can create a new python module file with a file name that does not conflict with other app. For example:
Polls/ models.py templatetags/ _ _ init__.py poll_extras.py views.py
Then you can use your custom tags and filters in your template file like this:
{% load poll_extras%}
Note:
The app containing the templatetags directory must be in the INSTALLED_APPS list
{% load%} load is the module name, not the app name
Remember to register with from django import template, register=template.Library ()
On how to analyze Django in the preparation of custom template tags tags and filter to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.