Skip to content
Advertisement

Django – Retrieve a session value to a form

I have a Django aplication and need to get a value from the session and put it in a HiddenInput.

I have this code in my view:

JavaScript

When I have some value on ‘obra_aberta_id’ I need to put this value on a HiddenInput:

JavaScript

But I’m getting an error on ‘request’: name ‘request’ is not defined

How can I get a value from the session e set os this HiddenInput?

I don’t know if the models will help, but there it is anyway:

JavaScript

Edit:

Here is my template:

JavaScript

And here is the view where I will use it:

JavaScript

Advertisement

Answer

Please remove from obra widget initial dict.

JavaScript

After that you can do:

JavaScript

But PLEASE read about Django-GCBV FormView. In your case:

JavaScript

I pass, your have a ModelForm. In this case you can use Django-GCBV EditView.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement