On Mon, 2007-06-11 at 21:42 +0000, eXt wrote:
> Hi all!
>
> Short version: Is it possible to access request from generic
> view's template and how to do that?
>
> Long version: I've a form I use to add an 'objects' to db. After I
> add my 'object' I call something like:
>
> <code>
> message = 'Your new object was created'
> return HttpResponseRedirect(reverse('object_detail',
> args=[object.id]) + '?message='+message)
> </code>
> *object_detail is a name of my view defined in urls.py
>
> As you see I perform redirect to another page and pass message
> parameter (get method). Page shown after redirect is a generic view
> (django.views.generic.list_detail.object_detail) which shows my
> template. Problem is: I'm not able to show 'message' parameter in this
> template. I tried: {{request.get.message}} and {{request.GET.message}}
> but nothing is shown.What is more the condition below evaluates to
> false:
>
> {% if request %}
> i've got a request!
> {% endif %}
>
> I'm confused - is there a request variable available in the context of
> generic view's template?
It doesn't by default. However, have a look at
http://www.djangoproject.com/documentation/templates_python/#django-core-context-processors-request
to see how to enable that. Generic views are given a RequestContext context,
so providing you enable the correct middleware processors, this will be
possible.
Once you have the "request" variable in your template, you can forget
about GET or POST. Just access the variable you want as an attribute on
the "request" (you can do this in Python, too). HttpRequest classes have
a __getitem__ method that allows you to treat them like a dictionary and
they will look for the variable in POST first and then GET.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---