You have two options:
you can extract the value in the view, and put it into the context
that is used to render the template.
you can access it using dot notation [1], which is used in templates
(templates are not python, you cannot write python in templates). Eg:
{% url url-name request.GET.page %}
Cheers
Tom
[1] https://docs.djangoproject.com/en/1.3/topics/templates/#variables
Best solution: calculate that url in your python view code and just pass
it along in the context.
The generic rule is that most processing should happen in python code,
not in your template.
Reinout
--
Reinout van Rees http://reinout.vanrees.org/
rei...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"
So instead of typing this in multiple views:
context['some_var'] = request.GET.get('name')
is somehow more effort than typing this in multiple templates:
{% url foo request.POST|mycustomattrgetter:"name" %}
The template code could be inherited, but then placing the variable in
a context could also be done by a template context processor. Where
you have many views that require the same context variables, this is
easier imo.
Remember that you can pass a custom list of template context
processors to a render_to_foo() call, in addition to
settings.TEMPLATE_CONTEXT_PROCESSORS.
Cheers
Tom
On Wed, Aug 10, 2011 at 7:06 PM, bruno desthuilliers
<bruno.des...@gmail.com> wrote:
> On 10 août, 16:35, Reinout van Rees <rein...@vanrees.org> wrote:So instead of typing this in multiple views:
>>
>> Best solution: calculate that url in your python view code and just pass
>> it along in the context.
>
> Definitly not the best solution if this has to work for more than
> exactly ONE view.
>
context['some_var'] = request.GET.get('name')
is somehow more effort than typing this in multiple templates:
{% url foo request.POST|mycustomattrgetter:"name" %}
The template code could be inherited, but then placing the variable in
a context could also be done by a template context processor. Where
you have many views that require the same context variables, this is
easier imo.