--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
template. The Library instance then calls its tag () method. For example:
Register.tag (' Current_time ', do_current_time)
The tag () method requires two parameters:
The name of the template tag (string).
The compilation function.
Similar to registering filters, you can also use the Register.tag adorner in Python2.4 and above:
@register. Tag (name= "Current_time") def do_current_time (parser,
Django Version: 1.9.5First set the templates in the same directory as manage.py, and then templates under the template file.Then set settings.py: Notice to change the yellow place.TEMPLATES = [ { ' backend ': ' django.template.backends.django.DjangoTemplates ', ' DIRS ': [ Os.path.join (Base_dir, ' Templates '). replace (' \ \ ', '/'),], # ' app_dirs ': True, ' app_dirs ': Fal
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
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
It took some time in recent days to create a tutorial and write several open-source blogs.An index is provided here to create an article on the skin of the QBlog template of the autumn Garden:
PS: at the same timeAutumn GardenIt also adds four skin sets. Currently, there are a total of eight skin sets.
1:ASP. NET open-source blog QBlog template creation Tutorial
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
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
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{{
Python one-day training 103 ---- Django template exercises, pythondjango
Requirements
Request. META is a Python dictionary that contains all the Header information of this HTTP request, such as the user IP address and user Agent. You can obtain this dictionary through request. META. items. You must output the META information to the webpage.
Output result
Source code index.html
Views. py
from django.shor
If you want the form form to submit a URL that is similar to action= "/index-5-6.html", you can use the {% url ' test1 ' param1=5 param2=6%} in the HTML template language urls.pyFrom django.conf.urls import URL, includefrom mytest import viewsurlpatterns = [ url R ' ^index-(? p. html ', Views.index, name= ' test1 '),]views.pyFrom django.http import httpresponsefrom django.shortcuts import renderfrom django.views import ViewDef index (req, param1 ,
If we need the template language to render the rendered HTML file to the front end when the backend has data dynamically extracted to the front endThe index function in our views.py has an S variable in the list that passes the data in curly braces to the {"list": s} to pass s to the list.The place to add the HTML is to use 2 curly braces to introduce the -------------------------------------------------------------------------------------------------
Usually in the first time to make a news blog template, it is difficult to grasp the direction. This tutorial will provide you with a reference on how to make WordPress news blog topics in Adobe Photoshop. This topic includes a header area, a picture rotation area (contains featured articles, recent messages, sorted by category, sidebar, widget). If you are a beg
-------------------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 ""
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.