because from the exception you return to process_request() and if you
don't return anything None in implied.



2016-04-20 15:10 GMT-03:00 Neto <[email protected]>:
> The problem is that when happens the exception, the redirect does not work,
> only if I put return before is_authenticated_user(), like this:
>
>
> class Check(object):
>
>     """
>         Check
>     """
>
>     @staticmethod
>     def process_request(request):
>
>         def is_authenticated_user():
>
>             try:
>                 request.session['user']
>             except KeyError:
>                 return redirect(reverse('mysite:login'))
>
>
>         return is_authenticated_user()  # why I need put "return" here?
>
>
>
>
>
>
> Em quarta-feira, 20 de abril de 2016 14:58:03 UTC-3, 술욱 زولوكْ escreveu:
>>
>> What's the value of request.session['user'] when user is not logged in?
>>
>> My guess is it's an instance of AnonymousUser.
>>
>> 2016-04-20 11:43 GMT-03:00 Neto <[email protected]>:
>> > Hi,
>> >
>> > I have a middleware that checks whether the user is logged in.
>> >
>> > class Check(object):
>> >
>> >     """
>> >         Check
>> >     """
>> >
>> >     @staticmethod
>> >     def process_request(request):
>> >
>> >         def is_authenticated_user():
>> >
>> >             try:
>> >                 request.session['user']
>> >             except KeyError:
>> >                 return redirect(reverse('mysite:login'))
>> >
>> >
>> >         is_authenticated_user()
>> >
>> >
>> >
>> > Why it does not works? How to solve?
>> >
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/7a9effe3-9fd3-42ff-bfd3-5ab7ea03030e%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1c984bab-f08f-4355-8aa2-c6e28b5ee579%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADut3oDsJqQM25didRRMJ4gnS%3Db5h6isj7urUORBseZ44eGjew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to