将django中的模型表单的媒体类处理到模板 [英] process the media class of a model form in django to a template

查看:98
本文介绍了将django中的模型表单的媒体类处理到模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的表单:

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",
            )

我处理此表单以查看模板。现在我想知道为什么Media类不会在模板中自动处理,至少它不会显示在.html输出中。

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.

因此,我想问我要做什么,以便媒体定义将显示在.html输出中。

Therefore i want to ask what i have to do in order that the media definitions will show up in the .html output.

我没有在django .docs中找到它。因此我以为会自动处理。

I did not find it in the django .docs. Therefore i thought it will be processed automatically.

推荐答案

您需要添加 {{form。 media}} 。对表单介质的引用不会自动插入。

You'll need to add {{form.media}} in the template yourself. References to form media are not inserted automatically.

这是非常困难的,因为包含< head> 部分的整个html文档都要输入由模板设计师和django将不得不猜测如果要自动尝试插入链接(这将非常难以猜测正确的JavaScript媒体 - 如果脚本之间有依赖关系)

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)

这篇关于将django中的模型表单的媒体类处理到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆