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.
This section briefly introduces how to load a template using the Python Django framework.
Generally, you store templates in the file system as files, but you can also use custom template loaders to load templates from other sources.
Django has two ways to load templates
Django
Django-Mako
Usage:1) Add a djangomako. Middleware. makomiddleware example to middleware_classes in settings. py of your Django project:MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware','djangomako.middleware.MakoMiddleware', )2) Add the
together with the include ()The parameters that are captured and the extra parameters are always passed to each row in the contained urlconf, regardless of whether the view for those rows requires these parameters. For example, the following two urlconf are functionally equivalent.#urls.pyfromdjango.conf.urls.defaultsimport* Urlpatterns=patterns ("," (R ' ^blog/
. context_processors.auth ', 'django. contrib. messages. context_processors.messages ',] ,},},]Template usage steps
(1) Add a new URL in URLs. py to display data.(2) create a view Function
Def all_stu (request): If request. method = 'get': stus = student. objects. all () return render(request,'stus.html ', {'students': stus}) # In page rendering, the first parame
ObjectsPerson_egon=person ("Egon") Person_alex=person ("Alex") Person_list=[Person_yuan,person_egon,person_alex]returnRender (Request,"index.html",{"L"L"DiC":d IC,"Date":d ate,"person_list":p erson_list})TemplateNote: A period character can also be used to refer to an object's methods (no parameter method):2, common filter of several templatesGrammar:{{Obj|filter__name:param}}DefaultIf a variable is false or empty, the given default value is used. Otherwise, the value of the variable is used. F
Django.conf.urls Import Urlfrom. Import viewsurlpatterns = [url (r ' ^$ ', views.index), url (r ' ^ (? PFinally, it is worth noting that the arguments in the views function are the default parameters that can be used, and that you can use regular expressions to set the parameters that are not captured (which can be us
The learning process of Django over the past few days is quite pleasant. Django adopts the MVC Architecture, and the learning curve is very gentle. Before learning deeply, first, record the methods that Django uses in the template to obtain data from the database. Zhixin zhi_^
First, let's assume a simple scenario wher
try to pass the parameters back again, the results are as follows:An 403 error occurred and the request was rejected. This is because the Django default configuration MIDDLEWARE_CLASSES in one middleware CSRF (cross-site request forgery), Wikipedia address (click here):‘django.middleware.csrf.CsrfViewMiddleware‘,The post request was verified.The first of these solutions:We first try to comment out this lin
not deleted{% spaceless%} "foo/">Foo{% Endspaceless%}The result is"foo/">FooSsiOutput the contents of a given file on a page{% ssi/home/html/ljworld.com/includes/right_generic.html%}Use the parsed parameter to make the input content available as a template so that the context of the current template can be usedparsed %}UrlReturns a reference to an absolute path (a
follow the active language (not yet understood here, this should and python internationalization related) translation URLs for details , see: internationalizationdocumentation.How Django handles a requestWhen a user requests a page from your Django site,The system determines which Python code should be executed according to the following arithmetic rules:
Django
Optional {% else %} tag. Only template variables and strings are supported, integers and decimals can be used as the {% ifequal %} tag parameters. Other types, such as the dictionary type, list type, and boolean type of Python, cannot be used.
In {% ifequal %.
22. Like HTML and other languages such as python, the Django temp
parameter in L #}
{{l.0}}
{# takes the value of key in the dictionary #}
{{D.name}}
{# Fetch the object's Name property #}
{{Person_list.0.name}}
{#. Operation can only invoke a method without parameters #}
{{Person_list.0.dream}} FiltersSyntax: {{value|filter_name: parameter}} Default {{value|default: "Nothing"}} Show nothing if value is not passed Length {{Value|length}} | No space around no space no spaces Returns the length of value, such as valu
', ' C ', ' d '], then the output is 4.filesizeformatFormat the value as a "human-readable" file size (for example,, ‘13 KB‘ ‘4.1 MB‘ , and ‘102 bytes‘ so on). For example:{{Value|filesizeformat}}If value it is 123456789, the output will be 117.7 MB .DateIf Value=datetime.datetime.now (){{value|date: ' y-m-d '}}SliceIf value= "Hello World"{{value|slice: ' 2:-1 '}}TruncatecharsIf the string character is more than the specified number of characters, it is truncated. The truncated string ends with
Django Template languageThe first template is just a text file that generates any text-based format (HTML, XML, CSS, etc.), contains variables in the template, replaces it with the final value when the template is rendered, and labels that control the logic of the template.T
The purpose of the Django template language is to strike a balance between strength and ease of use, and the Django template language is simpler and more exclusive than other template languages.Django template system consists of t
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.