django-request

Add a custom header on request in a Django middleware

China☆狼群 提交于 2020-03-26 06:08:11
问题 I want to implement a middleware in django, that will append a header on the request's existing headers, before the get_response(request) function. Though, when trying like this: request.headers['CUSTOM_HEADER'] = 'CUSTOM_VALUE' I get an error: 'HttpHeaders' object does not support item assignment Also in django's request (WSGIRequest), there is no add_headers function like the python's request module. Any ideas on how this can be accomplished? 回答1: Create a simple middleware as below, and

Error while accessing request.session['key'] inside forms. [using CheckboxSelectMultiple]

自作多情 提交于 2019-11-28 11:55:56
问题 I have two forms named GoodAtForm and PaidForForm . What these do is as follows... GoodAtForm Takes an input from a list in request.session['love'] and presents it to the user. Then user is presented with a CheckboXSelectMultiple fields so that users can select. After The form is submitted in the view, the user choices are then stored inside another list request.session['good'] . 4.Another Form named PaidForForm uses that list for further asking of questions from users using