I have a form looking like this:
class MarketingActionForm(forms.ModelForm):
contact = ManyToManyByLetter(Contact, field_name="first_name")
#contact = AjaxManyToManyField(Contact, DICT_LOOKUP)
class Meta:
model = MarketingAction
exclude = ('created_by',)
class Media:
js = (
settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js",
settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js",
settings.MEDIA_URL + "js/jquery.js",
settings.MEDIA_URL + "js/ajax_filtered_fields.js",
)
I process this form with a view to the template. Now I`m wondering why the Media class is not automatically processed in the template, at least it does not show up in the .html output.
Therefore i want to ask what i have to do in order that the media definitions will show up in the .html output.
I did not find it in the django .docs. Therefore i thought it will be processed automatically.
Working with form templates. All you need to do to get your form into a template is to place the form instance into the template context. So if your form is called form in the context, {{ form }} will render its <label> and <input> elements appropriately.
Rendering an attractive and easy-to-use web form requires more than just HTML - it also requires CSS stylesheets, and if you want to use fancy widgets, you may also need to include some JavaScript on each page.
Django Model Form It is a class which is used to create an HTML form by using the Model. It is an efficient way to create a form without writing HTML code. Django automatically does it for us to reduce the application development time.
You'll need to add {{form.media}}
in the template yourself. References to form media are not inserted automatically.
It would be very hard to do since entire html document including the <head>
section is to be typed by the template designer and django would have to guess where to insert the links if it were to attempt to do it automatically (it would be especially hard to guess correctly for the javascript media - if there are dependencies between scripts)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With