What I did
I have a view that calls a template with a form. In a certain case, I need to save some data in the session scope and send it to another url - which will call another view and another template.
My Problem
I created the session and redirected to the URL. This URL is pointing to MinhaSegundaView
, which calls a different form and template. I did a test and displayed the session data in the template using the session.order_id
syntax, and I wanted to do the same in my form FormDois
, as I use it to construct the inputs in the template. However, if I put initial
request
, it says that this element does not exist. I believe I did not have access to the request object.
What can I do?
My Code
Views.py
class MinhaView()
template_name = 'arquivo.html'
form_class = FormUm
def post()
request.session['order_id'] = order_id
HttpResponseRedirect(reverse('url_email'))
class MinhaSegundaView()
template_name = 'arquivodois.html'
form_class = FormDois
class FormDois(forms.Form):
order_id = forms.CharField(label=u'Pedido', initial=request.session['order_id'], required=True)