Найти - Пользователи
Полная версия: Middleware
Начало » Django » Middleware
1
del3d
Всем привет!
Возвращаю из view ответ:
render_to_response('index.html', {'a': 5})
А как мне в middleware в методе process_response() добавить к ответу еще одну переменную ‘user’, чтобы было так:
render_to_response('index.html', {'a': 5, 'user': 'Ivan'})
Александр Кошелев
Middleware пока работают только с уже готовыми request/response.

Если вы хотите добавить переменную в контекст перед рендерингом шаблонов, то для этого существуют контекст процессоры
del3d
Сделал так - работает..
def custom_proc(request):
return {
'usr': request.session['name'],
}

def main(request):
return render_to_response('index.html', context_instance = RequestContext(request, processors = [custom_proc]))
переменная usr передается шаблону.. но:
..context_instance = RequestContext(request, processors = [custom_proc]))
del3d
Спасибо, Александр Кошелев
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB