brian-zhao / google-app-engine-django

Automatically exported from code.google.com/p/google-app-engine-django
Apache License 2.0
0 stars 0 forks source link

Missing global context with render_to_response() from views #132

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1.
==== settings.py ====
.skip.
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
#    'django.middleware.doc.XViewMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
#    'django.core.context_processors.request',
)
INSTALLED_APPS = (
     'appengine_django',
     'django.contrib.auth',
     'myapp',
)
.skip.

2.
==== myapp/views.py ====
from django.shortcuts import render_to_response

def index(request):
    return render_to_response('base.html', {})

3.
==== urls.py ====
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

from myapp.views import index

urlpatterns = patterns('',
    (r'^url1/$', index),
    (r'^url2/$', direct_to_template, {'template': 'base.html'}),
)

4.
==== templates/base.html ====
<pre>{% filter force_escape %}{% debug %}{% endfilter %}</pre>

What is the expected output? What do you see instead?

Missing context in template with url1/, there are no variables from 
./django/core/context_processors.py in the Context, output of debug tag 
shows an empty dictionary.

What version of the product are you using? On what operating system?

Google App Engine Helper r86
Django 1.0.2 final
App Engine Python SDK 1.2.2

Please provide any additional information below.

It works with direct_to_template() with url2/ - context includes all 
variables from TEMPLATE_CONTEXT_PROCESSORS.

Original issue reported on code.google.com by osint...@gmail.com on 12 Jun 2009 at 9:19

GoogleCodeExporter commented 8 years ago
This is not a bug. If you’re using the render_to_response shortcut, just pass 
it as
the context_instance keyword argument to render_to_response, like so:

return render_to_response('base.html', {'some_var': 'foo'},
                           context_instance=RequestContext(request))

Don't fogive about:

from django.template import RequestContext

If you’re using a generic view, you don’t have to do anything except define 
the
TEMPLATE_CONTEXT_PROCESSORS setting; generic views use RequestContext by 
default. 

Original comment by osint...@gmail.com on 21 Jun 2009 at 7:10

GoogleCodeExporter commented 8 years ago

Original comment by m...@google.com on 8 Jun 2010 at 12:30