Ok Thank you very much both of you, and sorry about missunderstanding what
James said.
I understand it now.
I'll try it as soon as I arrive home.
Thank you.

2007/4/3, Karen Tracey <[EMAIL PROTECTED]>:
>
> I'll try to elaborate what James said.  (Did you consult the documentation
> links he pointed to?  They detail how you get the request object accessible
> in your templates, and thus your custom template tag.)
>
> In order to get access to the request object in your custom template tag,
> you must make some code changes elsewhere.  First you must include '
> django.core.context_processors.request' in your
> TEMPLATE_CONTEXT_PROCESSORS in settings.py.  Second, in the view that
> initially handles the request, you must pass a RequestContext (instead of a
> plain old Context) to your call to render_to_response.  Then, your template
> context will contain a variable 'request' that you can pass on to your
> custom template tag.  You can do this either by passing it in as another
> argument ({% menu position request %} instead of just {% menu position %})
> or you could investigate using the takes_context=True parameter on your
> register.inclusion_tag.
>
> Basically you have to go all the way back to the view that initially
> handles the request in order make sure that the request object continues to
> be accessible in your templates and in the custom template tag you have
> created.
>
> Hope this helps,
> Karen
>
> On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> >
> >
> > I don't know if I didn't understand you or if I you didn't don't
> > understand me :-)
> > Not sure abou what you are saying, I think I can't use it to make the
> > template tag work.
> > The template tag doesn't use a view to render the content, so it
> > doesn't get the request object as a parameter.
> > This is the code of the template tag:
> >
> > ----------------------------------------------------------------------------------------------------------
> > register = template.Library ()
> > def menu(position):
> >
> >         data = request.session["stored_data"]
> >         ...
> >         return {'output': output,}
> >
> > register.inclusion_tag('menu/menu.html')(bloque_menu)
> >
> > ----------------------------------------------------------------------------------------------------------
> >
> > So I need to read into data the data that is stored in the session.
> > But the request object is not accessible.
> > Sorry, I didn't understand what you wrote very good.
> > Thank you.
> >
> >
> >
> >
> >
> >
> > On 3 abr, 23:37, "James Bennett" <[EMAIL PROTECTED]> wrote:
> > > On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> > >
> > > > Inside the custom template tag, I don't get the request object since
> > > > it's not a view.
> > >
> > > Look into using RequestContext[1] in your views (generic views all use
> > > it automatically), and enabling the "request" context processor[2].
> > > This will make the variable "request" -- containing the HttpRequest
> > > object -- available in template contexts, so in your tag's 'render'
> > > method you could access it by doing something like:
> > >
> > > def render(self, context);
> > >     request = template.resolve_variable ('request', context)
> > >     ...do stuff with the request...
> > >
> > >
> > [1]http://www.djangoproject.com/documentation/templates_python/#subclass...
> > >
> > [2]http://www.djangoproject.com/documentation/templates_python/#django-c...
> > >
> > > --
> > > "Bureaucrat Conrad, you are technically correct -- the best kind of
> > correct."
> >
> >
> >
> >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to