和我一起
settings.py
和
urls.py
文件,我创建了一个
context_processors.py
同一目录下的文件。这是我的 context_processors.py 文件:
from django.contrib.auth.forms import AuthenticationForm
def loginFormCustom(request):
form = AuthenticationForm()
return {'loginForm': form,}
这是我的views.py:
from django.template import RequestContext
from tp.context_processors import loginFormCustom
def main_page(request):
variables = { 'title': 'This is the title of the page' }
return render(request, 'main_page.html', variables, context_instance=RequestContext(request, processors = loginFormCustom))
现在,当我运行它并转到调用 main_page 视图的 URL 时,它在 / 处给了我一个 TypeError:
'function' object is not iterable
并且回溯导致:
return render(request, 'main_page.html', variables, context_instance=RequestContext(request, processors = loginFormCustom))
知道为什么吗?我是否正确使用上下文处理器?