Answer the question
In order to leave comments, you need to log in
Django - how to pass parameters to a form?
Hello! Please help me with django. There is a FormView - a contact form for collecting email. How can I pass parameters to it not via URL ? Let me explain, there is an Item model, there is a list of items (ItemListView) - data about the selected item is loaded there via AJAX and information about it is displayed without reloading the page, as well as the "Submit request" button. The button displays the form (FormView) - without binding to the fields of the model. Here's how to make it so that the subject selected by the user is available in the form_valid of this form?
UPD:
Roughly speaking: I need the Item's ID - received using AJAX, to be sent to the FormView (contact form) (maybe I misunderstand and name something, I have a bad idea how it all works), in order to use this ID in the FormView for forming the body of the email, which is the FormView and sends. Oh how =)
Answer the question
In order to leave comments, you need to log in
Initial data
1) Get pk Item'a (id)
2) Change the Value of Input with JS.
Basically, you're contradicting yourself.
Pass parameters not via URLand
received with AJAX, send to FormView. There are several options here. Two correct ones, one curve:
/item/15/getform
, where 15 is the pk of your entity /getform?item=15
/getform
and pass the parameters of the POST request. In this case, they will not be visible in the URL.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question