Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate JS and CSS list output of media class object for Django form in template

I have simple question here. I know how to use django media in order to put js and css files which is specified in media class like this:

In forms.py for model

from django import forms

class CalendarWidget(forms.TextInput):
    class Media:
        css = {
            'all': ('pretty.css',)
        }
        js = ('animations.js', 'actions.js')

In template file

{{ form.media }}

However I want to put separately JS and CSS. It means I want to put CSS at head section and JS before body tag. So how I can achieve it using build in tags? Is it possible?

P.S. I cannot find out information from django documentation. (Perhaps, I look in wrong place). So give me a hint.

like image 459
Khamidulla Avatar asked Feb 14 '23 10:02

Khamidulla


1 Answers

You can use {{form.media.css}} and {{form.media.js}} separately to put them at required places.

Reference docs subsets-of-assets.

like image 157
Rohan Avatar answered Feb 17 '23 00:02

Rohan