Re: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
Thanks a lot, i did miss to pass 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 wrote: > On Thu, Feb 4, 2010 at 2:39 PM, weiwei wrote: > > Thanks.. > > > Here is my code > > You repeated the code for the template tag and the context processors > setting; that's not what I asked for. > > I still don't see the code for the view that renders the template that > includes the template tag you are working with. That is the code that must > specify a RequestContext if you want to access the variables set by the > request context processor in your template tag. The context processor won't > set variables in a plain Context, the view code (or whatever code is > supplying the context for the template render) must specify a > RequestContext. See for example 'some_view' under: > > http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 > > Karen -- 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: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
On Thu, Feb 4, 2010 at 2:39 PM, weiwei wrote: > Thanks.. > > Here is my code > > You repeated the code for the template tag and the context processors setting; that's not what I asked for. I still don't see the code for the view that renders the template that includes the template tag you are working with. That is the code that must specify a RequestContext if you want to access the variables set by the request context processor in your template tag. The context processor won't set variables in a plain Context, the view code (or whatever code is supplying the context for the template render) must specify a RequestContext. See for example 'some_view' under: http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 Karen -- 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: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
Thanks.. 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 wrote: > On Thu, Feb 4, 2010 at 1:41 PM, weiwei 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... > > > after i followed the answer i still got errors > > I do not see where you show the view code in that question. Possibly you are > not using a RequestContext to render the template? > > Karen -- 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: how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
On Thu, Feb 4, 2010 at 1:41 PM, weiwei 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-custom-template-tags > > after i followed the answer i still got errors > > I do not see where you show the view code in that question. Possibly you are not using a RequestContext to render the template? Karen -- 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.
how to activate DJANGO.CORE.CONTEXT_PROCESSORS.REQUEST
"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 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! -- 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.