I built a custom template tag and I wanna know if there is a way to access request.META in my template tag function.
I built a custom template tag and I wanna know if there is a
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.
Write your tag to accept
context, then accessrequestbycontext. For example for Simple tags:And ensure
requestis inside the templatecontext, by either passrequesttoContext();or add'django.core.context_processors.request'toTEMPLATE_CONTEXT_PROCESSORSin settings and useRequestContextfor rendering.Also, you could simply pass
request.METAtoContext()