Alibabacloud.com offers a wide variety of articles about django url parameters in template, easily find your django url parameters in template information here online.
The URL () function can be passed 4 parameters, two are necessary: regex and view, two are optional: Kwargs and name, below to see what these parameters are doing.URL () Parameter: Regex"Regex" is often used as an abbreviation for regular expressions, and regular expressions are a syntax for pattern matching of strings, which for us is a match for
Goal
Set up a book list page, display book name lists, and achieve click on the title to jump to the book details page, display the book details.
Introduction to URL methods
Function: Returns a reference to an absolute path (a URL that does not contain a domain name); The reference matches a given view function andSome optional parameters
register this tag with the Library instance of your module. Registering a custom tag is similar to registering a custom filter (as described above ). You only need to instantiate a template. Library instance and then call its tag () method. For example:
Register. tag ('current _ time', do_current_time)
The tag () method requires two parameters:
Template Tag N
%}{% endifequal%} The arguments can be hard-coded, so the following examples are valid:'sitenews'%}{% endifequal%} {% ifequal section "community"%}{% endifequal%}Similar to {%if%}, the {%ifequal%} tag also supports option {%else%}'sitenews'%}Else%}{% Endifequal%} Only template variables, characters, integers, and floating-point types can be used as comparison parameters, here are some valid examples:{
FAQs about template writing in django: compiling djangotemplate
Django's typical MTV model recently encountered some numerical problems on the template. Compared with jsp used in java, the thymleaf template may be somewhat different and sometimes more convenient;
Django
ReproducedThe original author basically writes the contents of the Django website to the translator, translating the address http://python.usyiyi.cn/django/ref/templates/builtins.html# Built-in-filter-reference Second, filter
1. The filter can be used to modify the display of the variable, the form of the filter is: {{variable | filter}}, pipe symbol ' | ' Represents the use
of filters 2. Filters can be use
Let's create a simple website by django ...STEP01:Django-admin Startproject x01STEP02:CD x01 lsYou'll see ...Or you can use the tree:TreeSTEP03:Write the first view for your website ...CD X01vim views.pyWrite the below code into your new file (views.py from Import HttpResponse def Hello (Request): return HttpResponse ("HelloWorld")STEP04:Let the Django know y
With the Django development site, you can design very beautiful URL rules, if the URL matching rules (including regular expressions) are better organized, the structure of the view will be more clear, easier to maintain. But there may be some misunderstanding, the following will be summed up below. Hope to be useful to everyone.
Problem:
The video I was studying
the Library instance, so that you can use the Django template language:
Register.filter (' Cut ', cut)
register.filter (' lower ', lower)
The Library.filter () method requires two parameters:
The name of the filter (a string)
Filter function itself
If you are using a Python 2.4 or newer version, you can use the adorner register.filt
the second and third parameters. (Multi-Debug)
3. Configure the Urlpatterns variable in the urls.py file (mainly highlight this line):
Copy the Code code as follows:
Urlpatterns = Patterns ("',
URL (r ' ^$ ', home),
URL (r ' ^static/(? P
. *) $ ', ' Django.views.static.serve ', {' Document_root ': Settings. Static_root}),
)
4. Test the
be able to modify the path correctly by adjusting the second and third parameters. (Multiple debugging)
3. Configure the Urlpatterns variable in the urls.py file (mainly to highlight this line):
Copy Code code as follows:
Urlpatterns = Patterns ("",
URL (r ' ^$ ', home),
URL (r ' ^static/(?) p)
4. Test the above configuration:
view functions do not have to check for ' Request.method ', because ' method_splitter () ' has done it for them. (for example, when "Some_page_post ()" is called, we can be sure that the value returned by ' Request.method ' is ' post '. Of course, it's safer and better to document the code, and here's the assumption that ' request.method ' can work as we expect.
Now we have a nice, generic view function that encapsulates a program that assigns a different view by the return value of ' Request.m
To avoid using the hard-coded URL in the template, you can use the {% URL%} template label to resolve可以用以下方法替换注:detail是url中使用name参数定义url(r‘^(?P如果多个应用中避免名字冲突,可以使用命名空间在项目的URL中使用urlpattern
operation is less efficient than truncatewords, it is only considered when value is in HTML format.42, UpperConvert a string to uppercase43, UrlEncodeTo UrlEncode a string44, UrlizeMeaning: Converts a URL in a string into a clickable form.Use form: {{value | urlize}}For example, if value is a check out www.djangoproject.com, then the output will be:Check out 45, UrlizetruncUse form: {{value | urlizetrunc:15}}Meaning: Same as (43), but a little differ
if Queryset is None: Queryset = Self.get_queryset () # Next, tr
Y looking up by primary key. PK = Self.kwargs.get (Self.pk_url_kwarg, None) slug = SELF.KWARGS.G ET (Self.slug_url_kwarg, None) if PK. Not None: que Ryset = Queryset.filter (PK=PK)
From the Get method, we can see that PK is the Get_object () method used to filter our Queryset parameters.
and PK This variable, is through the Kwargs get method, which Pk_
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
Templates are usually used to generate HTML, but Django templates can also generate any document based on text format.
The text enclosed in two braces (for example, {person_name}) is called a variable ).
The text enclosed by braces and percent signs (for example, {% if ordered_warranty %}) is a template tag ). Tags are clearly defined, that is, labels that only notify the
Grappelli is the most star Django template system on GitHub
Http://django-grappelli.readthedocs.org/en/latest/quickstart.html#installation
The code is as follows:
Pip Install Django-grappellisettings.py
Installed_apps = (' Grappelli ',' Django.contrib.admin ',)
Add URL en
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.