Saturday, December 28, 2013

Re: Accessing attributes of the current view in Django middleware?

Since the request is simply a dictionary, can you not append that attribute to it?

On 28/12/2013 7:41 am, "alk...@gmail.com" <alexington@gmail.com> wrote:

I'm trying to access an attribute of the current view instance in the middleware layer.

For example, given a class-based view like this:

  # views.py  class MyView(View):      my_attribute = 'something'

I'd love to be able to get a handle on my_attribute in the middleware by doing something like this:

  # middleware.py  def process_view(self, request, view_func, view_args, view_kwargs):      my_attribute = request.view.my_attribute

Of course, this does not work because Django doesn't expose the view instance through the request object.

Is there any way to get this accomplished?

Many thanks!

--
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/0dbc397b-0d9b-4382-be8c-a55f818e4ec1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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/CAHqTbjmMavdAjx8h23o%2BkeCKTvjVsUseDSmhQO_EDsEg4ehsvA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment