{# title = More About Contexts #} {# foo = 1234.5 #} {# bar = [ 100, 200, "Hello World" ] #} {% load pytags %}
{# title = More About Context #}
{% endverbatim %}
at the top of the HTML page will create the variable title
that
can be used in the page as {% verbatim %}{{ page.title }}
{% endverbatim %}
to produce: {{page.title}}
To add more variables list them one on each line. To add data beyond a simple string use the JSON format:
{% code "django-comments" %}
Note that in the last example for bar
gets turned into python list accessible as
{% verbatim %}{{ page.bar }}
{% endverbatim %}
to produce {{page.bar}}.
The {% verbatim %}{{ page.bar }}
{% endverbatim %} object can also be looped over with Django
to produce:
{% for elem in page.bar %}
* {{ elem }}
{% endfor %}
The second method of getting context into a page is a python module named context.py
placed in the directory root. This may contain
any python construct.
The content of this module will be visible under the parameter data
{% verbatim %}{{ context }}
{% endverbatim %} variable name.
{% code "context.py" lang='python' %}
We can now access the contenxt of `contex.py` like
so {% verbatim %}{{ context.greeting }}
{% endverbatim %} to produce: {{ context.greeting }}
Go back to: {% link "index.html" "Home Page" %}.
{% endmarkdown %}