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:
我有一个简单的问题。我知道如何使用django媒体来放置js和css文件,这是在媒体类中指定的:
In forms.py for model
在形式。py为模型
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?
但是我想要分别使用JS和CSS。这意味着我想把CSS放在head部分,JS放在body标签之前。那么,如何使用标签构建实现它呢?是可能的吗?
P.S. I cannot find out information from django documentation. (Perhaps, I look in wrong place). So give me a hint.
附注:我无法从django文档中找到信息。(也许我看错地方了)。给我一个提示。
1 个解决方案
#1
7
You can use {{form.media.css}}
and {{form.media.js}}
separately to put them at required places.
您可以使用{ { form.media。css } }和{ { form.media。将它们分别放在所需的位置。
Reference docs subsets-of-assets.
参考文档subsets-of-assets。
#1
7
You can use {{form.media.css}}
and {{form.media.js}}
separately to put them at required places.
您可以使用{ { form.media。css } }和{ { form.media。将它们分别放在所需的位置。
Reference docs subsets-of-assets.
参考文档subsets-of-assets。