Re: RequestContext and user.is_authenticated confusion

2010-02-14 Thread Kev Dwyer
On Sun, 14 Feb 2010 08:30:05 -0800, Achim Domma wrote:

> Hi Kev,
> 
> thanks for the hint. Trying different solutions I introduced indeed a
> typo. Now I can see the username and is_authenticated works as expected.
> But still curious: Is there a good reason, why I have to pass
> RequestContext each time? Whenever I'm using Django and having the
> feeling to violate DRY, there's usually a better solution. I'm quite
> surprised that it's not the case this time!?
> 
> cheers,
> Achim

Hello Achim,

I'm glad it's working for you now.

I don't know the original reason for having to use RequestContext; there 
is a hint in bug #650 that authentication wasn't thought to be a
common enough use case to justify the processing overhead of making
RequestContext available by default.

The idea of adding RequestContext to render_to_request by default was 
considered for 1.1 but special-cased, apparently because consensus could
not be reached.  Search the Django Developers list if you want the details.

All the best,

Kev


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: RequestContext and user.is_authenticated confusion

2010-02-14 Thread Achim Domma
Hi Kev,

thanks for the hint. Trying different solutions I introduced indeed a
typo. Now I can see the username and is_authenticated works as
expected. But still curious: Is there a good reason, why I have to
pass RequestContext each time? Whenever I'm using Django and having
the feeling to violate DRY, there's usually a better solution. I'm
quite surprised that it's not the case this time!?

cheers,
Achim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: RequestContext and user.is_authenticated confusion

2010-02-14 Thread andreas schmid
Kev Dwyer wrote:
> On Sun, 14 Feb 2010 01:19:41 -0800, Achim Domma wrote:
>
>   
>> Hi,
>>
>> depending on if a user is logged in or not, I want to display a "login"
>> form or a "logout" button. I tried to use this code snippet:
>>
>> http://docs.djangoproject.com/en/1.1/topics/auth/#id6
>>
>> If I render my view using render_to_response("myTemplate.html") the user
>> variable is empty. If I use
>> render_to_response("myTemplate.html",context_instance=RequestContext(request))
>> I get the correct user and can display the username. But
>> is_authenticated still always returns false!? Any hint what I might be
>> doing wrong?
>>
>> According to the documentation
>> "context_instance=RequestContext(request)" should only be required when
>> passing a additional data dictionary to render_to_response. As passing
>> data to a view and checking if the user is logged in should be something
>> quite common, this sounds strange to me!?
>>
>> I want to display the user information / status in my master template,
>> so having to pass a RequestContext into the template from each view
>> would be very tedious. Feels like I'm on a complete wrong way!?
>>
>> Any hint would be very appreciated!
>>
>> cheers,
>> Achim
>> 
>
> Hello Achim,
>
> It's difficult to tell why is_authenticated returns false for you, but
> assuming there aren't any typos in your template then you need to check 
> that your views are working correctly, particularly that authentication
> are not "lost" by forgetting to pass them to one of your views.
>
> Passing a RequestContext to your templates is the correct way to give your 
> templates access to authentication information.  It seems cumbersome
> while your changing all your render_to_response calls but it doesn't
> need any maintenance after that.
>
> Cheers,
>
> Kev
>
>   
did you put 'django.core.context_processors.request' into your
TEMPLATE_CONTEXT_PROCESSORS in your settings.py?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: RequestContext and user.is_authenticated confusion

2010-02-14 Thread Kev Dwyer
On Sun, 14 Feb 2010 01:19:41 -0800, Achim Domma wrote:

> Hi,
> 
> depending on if a user is logged in or not, I want to display a "login"
> form or a "logout" button. I tried to use this code snippet:
> 
> http://docs.djangoproject.com/en/1.1/topics/auth/#id6
> 
> If I render my view using render_to_response("myTemplate.html") the user
> variable is empty. If I use
> render_to_response("myTemplate.html",context_instance=RequestContext(request))
> I get the correct user and can display the username. But
> is_authenticated still always returns false!? Any hint what I might be
> doing wrong?
> 
> According to the documentation
> "context_instance=RequestContext(request)" should only be required when
> passing a additional data dictionary to render_to_response. As passing
> data to a view and checking if the user is logged in should be something
> quite common, this sounds strange to me!?
> 
> I want to display the user information / status in my master template,
> so having to pass a RequestContext into the template from each view
> would be very tedious. Feels like I'm on a complete wrong way!?
> 
> Any hint would be very appreciated!
> 
> cheers,
> Achim

Hello Achim,

It's difficult to tell why is_authenticated returns false for you, but
assuming there aren't any typos in your template then you need to check 
that your views are working correctly, particularly that authentication
are not "lost" by forgetting to pass them to one of your views.

Passing a RequestContext to your templates is the correct way to give your 
templates access to authentication information.  It seems cumbersome
while your changing all your render_to_response calls but it doesn't
need any maintenance after that.

Cheers,

Kev

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RequestContext and user.is_authenticated confusion

2010-02-14 Thread Achim Domma
Hi,

depending on if a user is logged in or not, I want to display a
"login" form or a "logout" button. I tried to use this code snippet:

http://docs.djangoproject.com/en/1.1/topics/auth/#id6

If I render my view using render_to_response("myTemplate.html") the
user variable is empty. If I use
render_to_response("myTemplate.html",context_instance=RequestContext(request))
I get the correct user and can display the username. But
is_authenticated still always returns false!? Any hint what I might be
doing wrong?

According to the documentation
"context_instance=RequestContext(request)" should only be required
when passing a additional data dictionary to render_to_response. As
passing data to a view and checking if the user is logged in should be
something quite common, this sounds strange to me!?

I want to display the user information / status in my master template,
so having to pass a RequestContext into the template from each view
would be very tedious. Feels like I'm on a complete wrong way!?

Any hint would be very appreciated!

cheers,
Achim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.