[Django] Context Manager

Context Manager
django to extract the data context for the template calls

Requirements: All pages require a specific variable

Essence: python function that takes a parameter HttpRequest object and returns a dictionary must be

Define the context manager
filename naming unrestricted, unfettered path is also placed, it can be placed anywhere in the django project

definition

my_name DEF (Request):
return { 'name': 'Jack'}
. 1
2
to write in to register after settings.py

= TEMPLATES [
...
'context_processors': [
...
'firstapp.customer_context.my_name' (http://www.amjmh.com)
...
. 1
2
. 3
. 4
. 5
. 6
Registration good profiles may all in use, the {{name}} is added to the model may be displayed

...
<body>
{{name}}
<form Action = "" Method = "POST">
...
. 1
2
. 3
. 4
. 5
, if there is a context manager, and contextual data (context) at the same time, they are executed in the order , and if both have the same variable name, context into force
---------------------

Guess you like

Origin www.cnblogs.com/ly570/p/11322883.html