Answer the question
In order to leave comments, you need to log in
What is the best way to use javascript in django forms?
Hello.
The task arose, when writing your own form widgets, to attach javascript to them. Moreover, javascript must be with the parameters specified during the initialization of the form fields. There can be several such widgets in a form. At the moment I see the following options:
1. javascript built into the widget template;
2. render the javascript template with the necessary variables, save it to media resources and attach it via the Media widget (then if several such widgets are used in the form, I will have as many small files, which does not look very good)
3. Your option, which will solve everything my problems :)
The question is, how do you think it's better to attach such javascript to widgets?
Answer the question
In order to leave comments, you need to log in
Write one generic javascript, and pass the parameters through the data- attributes of the html elements when rendering the widget.
One js file is better because it can be easily embedded into a common minified js for the entire site.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question