session - Getting username in Django on every single page regardless of how I got there -


this more theory question specific code problem.

i'm kinda confused how information username, user email, etc. stored , accessed in django.
know:
can access {{user.username}} if got here using render() or render_to_response() requestcontext inside. if got on page using httpresponseredirect don't have access user.username , blank here.

what want know:
there way access user data every single page regardless of how got there? mean if don't use views @ all, manually typing address.
strangely enough, thought data username accessible through sessions, 9 out of 10 articles topic talk requestcontext , other stuff passes values 1 page another.

i read custom context processors, think specific purposes, not simple username.

so maybe in nutshell question is:
if want display example username in corner of every single page of site - how should that?

what happens here (for dummies)
httpresponseredirect doesn't affect @ all. problem is redirecting render_to_response() call not include requestcontext. if not specify requestcontext write out blank , force on session data given context_processor.auth, have nothing @ context data @ page.

how should done(in opinion) use render() or render_to_response() requestcontext in of views, don't forget it. , don't worry @ various redirects since not affect context data. static html pages context data processor, works, fault didn't check twice beforehand.

just output {{ user.username }}. if user logged, of auth middleware , django.contrib.auth.context_processors.auth context processor enabled username shown.

the middleware takes user id session, loads user db , sets request.user attribute. context processor takes request.user attribute , injects requestcontext user variable.

to make user variable available in template should use render() shortcut. or render_to_response() requestcontext context_instance argument.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -