I’m using direct_to_template for a url but I need the logged in user to display the page. How do I pass it to direct_to_template?
I’m using direct_to_template for a url but I need the logged in user to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your
TEMPLATE_CONTEXT_PROCESSORSvariable insettings.pyis set to include'django.contrib.auth.context_processors.auth', it will already be on the page context. (This is configured by default).The
direct_to_templategeneric view usesRequestContext, so there will be a context variable calleduserthat will provide the currently logged in user (or anAnonymousUserif there is no logged in user).For example, to display the username in your template:
{{ user.username }}.For more details see the django docs on the auth context processor.