Questions tagged «django-context»

4
在Django中创建我自己的上下文处理器
我已经到了需要将某些变量传递到所有视图(主要是自定义身份验证类型变量)的地步。 有人告诉我编写自己的上下文处理器是执行此操作的最佳方法,但是我遇到了一些问题。 我的设置文件如下所示 TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.contrib.messages.context_processors.messages", "sandbox.context_processors.say_hello", ) 如您所见,我有一个名为“ context_processors”的模块和一个名为“ say_hello”的函数。 看起来像 def say_hello(request): return { 'say_hello':"Hello", } 我是否可以假设自己现在可以在我的观点范围内进行以下操作? {{ say_hello }} 现在,这在我的模板中什么也没有渲染。 我的观点看起来像 from django.shortcuts import render_to_response def test(request): return render_to_response("test.html")
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.