2

While using a class-based view like:

from django.views.generic.edit import CreateView
from myapp.models import MyModel

class MyModelCreateView(CreateView):
    model = MyModel

How can I define custom CSS and JavaScript to be loaded by {{ form.media }} in the myapp/mymodel_form.html template?

I could set the form_class attribute and use the Media subclass, but I'm wondering if there's direct way without creating more classes.

4

1 回答 1

0

有媒体属性

https://docs.djangoproject.com/en/1.6/topics/forms/media/#dynamic-property

如果您正在寻找简单性,另一种方法是通过在基本模板中创建一个媒体块并在子模板中指定您的媒体来使用模板继承。但是,它可能会重复媒体定义。

于 2013-12-16T07:37:07.093 回答