15(b). Let us understand what we wrote in edit_contact.html in django project-(Tags)

Template Tags

Fundamental template tags

using

The tag using allows you to avoid repeated references to a Python dictionary in a template or dashboard report. This is a block tag with syntax
{% using <dictionary> %} ... {% endusing %}
For example:
if the 'targets' variable holds a dictionary of Congressional information, write
{% using targets %}
    Call {{ title_last }} and tell {{ them }} that {{ they }} should
    vote no:

    {{ listing_html|safe }}
{% endusing %}
instead of:
Call {{ targets.title_last }} and tell {{ targets.them }} that
{{ targets.they }} should vote no:

{{ targets.listing_html|safe }}

Arithmetic template tags

divide

The tag divide performs floating point division, and takes three arguments: top, bottom, and precision.
For example:
{% divide 72 499 2 %}
returns "0.14"

save_sum

The tag save_sum takes the sum of an arbitrary number of template variables and saves it to a new variable that you specify. The syntax is:
{% save_sum this that as those %}
If only one variable is specified, then save_sum allows you to copy a variable.

sign_difference

The tag sign_difference compares its two numeric arguments and returns a "-" string if and only if the first argument is less than the second. Otherwise it returns an empty string.

Miscellaneous template tags

localtime

The tag localtime formats a particular datetime value, say an updated_at column or {{ now }} above, according to a particular format string or relative_time which smartly picks a format from 1:30 am, Jan 31, or Jan 31 2009. For example:
{% localtime object.updated_at "m/j/y, P" %}

record

The tag record is used take a specified value or variable and append it to a specified list. The list is created if necessary, and an optional argument reportresult will tell the template tag to extract an integer result from an HTML tag. This tag can be used within a for loop to build a series of report results at different points in time or for different pages.
For example:
{% record reportresult progress_users in series_users %}

appends the current value of ``{{ progress_users }}`` to the list ``{{ series_users }}``, creating it if necessary.

required_parameter

The tag required_parameter is a dummy tag used in Dashboard Reports to indicate to ActionKit that a parameter is required from the user. For example, our built-in dashboard event_report contains:
{% required_parameter "campaign_name" %}
ActionKit sees this and prompts the user to enter a value for campaign_name. After using the above tag, the variable {campaign_name} is available in the report (note the single braces).

requires_value

The tag requires_value takes one argument, and raises a Template Syntax Error if the value of the argument is not available or resolves to False. This is useful in mailing snippets.
For example,
{% requires_value targets.count %}
ensures that code involving targets will display in that email.

right_now

The tag right_now creates the variable {{ now }} that contains the Python datetime object datetime.now(). You would include this once in your template as
{% right_now %}
before using filters like now|months_until and now|months_past.
Right_now also adds to context a variable {{ months_for_chart }} that is necessary to create the x-axis for our month-by-month bar graph charts used in certain dashboards.

select_index

The tag select_index takes a list, an index, and a variable name to save list[index] to.
For example:
{% select_index dogs 3 as dog %}

No comments:

Post a Comment