【发布时间】:2011-01-15 20:18:25
【问题描述】:
我有一个奇怪的问题,我想使用上下文处理器添加一个全局查询。 这就是following我的做法:
在我的应用程序中创建了一个 processor.py:
from myproject.myapp.models import Foo
def foos(request):
return {'foos': Foo.objects.all()}
在我的 setting.py 末尾我添加了这个:
TEMPLATE_CONTEXT_PROCESSORS = ('myapp.processor.foos',)
最后,我的观点是这样的:
def index_view(request):
return render_to_response('index.html', {}, context_instance=RequestContext(request))
在我的 index.html 模板中:
<select id="select_foo">
{% for foo in foos %}
<option value="/{{ foo.slug }}">{{ foo.name }}</option>
{% endfor %}
</select>
最后是我的网址:
(r'^$', 'myapp.views.index_view'),
我的 foos 显示没有任何问题,但是我的 media_url 和其他上下文消失了。 可能是什么问题
【问题讨论】:
标签: python django django-templates