http://docs.djangoproject.com/en/dev/ref/templates/api/
But i didn't find how to activate it
Here is my question
http://stackoverflow.com/questions/2160261/access-request-in-django-custom-template-tags
after i followed the answer i still got errors
TemplateSyntaxError at / Caught an exception while rendering:
'request' Original Traceback (most recent call last): File "C:
\Python25\lib\site-packages\django\template\debug.py", line 71, in
render_node result = node.render(context) File "C:\Python25\lib\site-
packages\django\template__init__.py", line 936, in render dict =
func(*args) File "c:\...\myapp_extras.py", line 7, in login request =
context['request'] File "C:\Python25\lib\site-packages\django\template
\context.py", line 44, in getitem raise KeyError(key) KeyError:
'request'
tho code causing problem is
request = context['request']
Thanks for any help!
"DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every
RequestContext will contain a variable request, which is the current
HttpRequest. Note that this processor is not enabled by default;
you'll have to activate it. " from this page
http://docs.djangoproject.com/en/dev/ref/templates/api/
But i didn't find how to activate it
Here is my question
http://stackoverflow.com/questions/2160261/access-request-in-django-custom-template-tags
after i followed the answer i still got errors
Here is my code
from django import template
from django.template import RequestContext
register = template.Library()
@register.inclusion_tag('userinfo.html',takes_context = True)
def userinfo(context):
request = context['request']
address = request.session['address']
return {'address':address}
and request = context['request'] causing problem, seems context
doesn't have a key 'request'
And i do have
TEMPLATE_CONTEXT_PROCESSORS =(
"django.core.context_processors.request",
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
)
in settings.py
On Feb 4, 11:17 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Thu, Feb 4, 2010 at 1:41 PM, weiwei <online.service....@gmail.com> wrote:
> > "DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
> > If TEMPLATE_CONTEXT_PROCESSORS contains this processor, every
> > RequestContext will contain a variable request, which is the current
> > HttpRequest. Note that this processor is not enabled by default;
> > you'll have to activate it. " from this page
>
> >http://docs.djangoproject.com/en/dev/ref/templates/api/
>
> > But i didn't find how to activate it
>
> You activate it by including it in TEMPLATE_CONTEXT_PROCESSORS in
> settings.py. That is all you have to do.
>
> > Here is my question
>
> >http://stackoverflow.com/questions/2160261/access-request-in-django-c...
Thanks..
Here is my code
context_instance=RequestContext(request) in
my view code
def access(request):
return
render_to_response('tool.html',context_instance=RequestContext(request))
after I added "context_instance=RequestContext(request)"
It is working now like a charm!
Thanks again!
On Feb 4, 11:54 am, Karen Tracey <kmtra...@gmail.com> wrote: