Wednesday, April 1, 2015

Re: Global access to request.user

On Wed, Apr 1, 2015 at 3:43 AM, Thomas Güttler <hv@tbz-pariv.de> wrote:
> Headache makes the code which gets called outside the request-response
> cycle.
> For example cron jobs.
>
> Example: We create reports for users in cron jobs. Here we need a user
> object
> and have no context.

You still have a Context object; you always have one if you're in the
render phase. Your context just won't be a RequestContext object, so
the hooks in TEMPLATE_CONTEXT_PROCESSORS won't know how to get "user".

But when you create the Context yourself you can pass in whatever
value for "user" is appropriate. Your templates won't know the
difference between rendering in a cron, management command, or request
cycle.

https://docs.djangoproject.com/en/1.7/ref/templates/api/#rendering-a-context

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD4ANxUJgBx5t4PsEJL_jFbuYHGSkH8xtPVvniE%2BJ-j5JzCihQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment