Filter:1. built-in: Filter1.{{value|date: ' Y-m-d h:i:s '}}2 .....2. Custom Filter1. Create a new Templatetags (Python package) in the app2. Create a new py file with a name3. Internal definition An implementation provides specific function functions, which are registered in the Django template language in a fixed notation:From Django Import TemplateRegister =
--HTML escape# will include HTML tags output, not interpreted execution, because when the user commits the # string, may contain some offensive code, such as JS script;--Automatically escaped characters in Django# --Use escape filter when displaying variables that are not trusted# {{T1|escape}} omitted to write, for Django to be automatically escaped;--Close Escape (HTML tags can be interpreted to execute)-
In the article Django implements the custom template page and adds a custom jump link in the Admin Site App module (a) we succeeded in/feedback/feedback_stats/ The path customizes the HTML file using the template syntax, completing the function of jumping to the custom statistics page via the corresponding link, but not being able to add the displayed jump link s
In web development, a lot of the time will be the introduction of common head and tail, below I record the introduction of common head and tail in the Django template example, Novice, do not spray, there is wrong place to write, please help to point out, thank you1, first create a common template file, paste my HTML template
Django template Principle
# Create a template object. The context object transmits the values required by the template, and the render method is used to present the template.
# Write a template, create a
What we're seeing is just some pre-populated data in the template, and we have to let it show the data from the database for the article. Here's a little makeover for the template:Remove all article tags, and then add the following to populate the template variable {{post_list}} with the content read from the database{% forPostinchPost_list%} class="post post-{{post.pk}}"> class="Entry-header
this question so, Easy , put python the string is wrapped and replaced HTML the line break is not OK , as follows:Result=result.repalce (' \ n ', ' but, result and disappointments still no effect (if so, you will not see this article), As shown on the template page - - ! Look at the source code found " " and ">"was parsed into: ", We need to get a foot on the template:{{Ok1_message|safe}}This article is f
Filter filter Main form: variable | function, which means to give the variable to the function processing, and the custom filter is to define the function itself, because there are few.A. Create the Templatetags module in the app (required)B. Create a. py file in Templatetags, such as my_tags.py fromDjangoImportTemplate fromDjango.utils.safestringImportMark_saferegister= Template. Library ()#The Register's name is fixed and cannot be changed .Correspo
Extends and block are a pairThey are used for inheritance of master and child versionsUse {% block xxx%} in the master HTML for some parts that need to be replaced ... {% Endblock%},In the child HTML, the first line needs to write the master to inherit, {% extends ' master relative path '%} to introduce the master.IncludeThe introduction of the Include user public template is a good way to introduce a public templ
A. Regular URL (solves the problem that the regular part cannot be matched)-------xxx.html"/teacher_edit-{{Item.id}}"> Edit Url.pypath ('teacher_edit-(\d+)', Views.teacher_edit),--------views.pydefTeacher_edit (req): xxxx########################## #以上的正则url不能被识别, the workaround is as follows:----------------urls.py fromDjango.urlsImportPath,re_path#Introducing the Re_path moduleRe_path ('teacher_edit-(\d+)', Views.teacher_edit),#here is a regular part (\d+), so there is a parameter passed to Tea
I. Resource Utilization:
1. For more information, see the Python/Django official website.2. In addition, visit the blog Park, csdn and other related technical articles.It is not recommended to ask questions in the QQ group, because many people are tough people, and they do not discuss technology, but discuss things in disorder. In addition, they are inefficient at ignoring the questions raised by many people.
Ii. Module Learning
1. python dat
Django Template System Master Board"en">"UTF-8"> "x-ua-compatible"Content="Ie=edge"> "Viewport"Content="Width=device-width, initial-scale=1"> {% Block Page-css%} {% Endblock%}{% Block Page-main%}{% Endblock%}{% Block Page-js%}{% Endblock%}Note: We usually define the CSS blocks and JS blocks for the page in the motherboard, which is convenient for the sub-page substitution.Inherit the master boardIn the
Extends and block together.They are used for inheritance of master and child versionsUse {% block xxx%} in the master HTML for some parts that need to be replaced ... {% Endblock%},In the child HTML, the first line needs to write the master to inherit, {% extends ' master relative path '%} to introduce the master.IncludeThe introduction of the Include user public template is a good way to introduce a public templa
-------------------Django Built-in filter-------------------1. AddUsed in the form: {{value | add: ' 2 '}}Meaning: Increase value by 22, AddslashesUsing the form: {{value | addslashes}}Meaning: Add a backslash before the quotation mark in value3, CapfirstUsing the form: {{value | capfirst}}Meaning: The first character of value is converted to uppercase form4. CutUse the form: {{value | cut:arg}}, for example, if value is "String with spaces" Arg is ""
In web development, a lot of the time will be the introduction of common head and tail, below I record the introduction of common head and tail in the Django template example, Novice, do not spray, there is wrong place to write, please help to point out, thank you1, first create a common template file, paste my HTML template
Reprinted from: Http://www.lidongkui.com/django-template-filter-tableFirst, form: lowercase{{name | lower}}Second, the filter can be nested, the string through three filters, the first filter is converted to lowercase, the second filter output the first letter, the third filter to convert the initial letter to uppercaseLabel{{Str|lower|first|upper}}Three, the parameters of the filterShow Top 30 characters{{
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.