如何在Django Crispy Forms中包含HTML标头标签?

时间:2013-01-10 20:41:36

标签: django django-crispy-forms

我有以下要转换为django crispy表单的HTML段:

    <div class="span5">
        <h3 class='offset1'>Select images</h3>
        <div id='image-drop' class='dropzone span5 center'>
            <p>Drag and drop photos and video here</p>
            <p class='big'>+</p>
            <p>Or click to add using the file browser</p>
        </div>
    </div>

如何添加标记和

标记?我试过这个:

    self.helper.layout = Layout(
        Div(css_class='span5',
            HTML("<h3 class='offset1'>Select Images</h3>"),
            Div(css_id='image-drop',
                css_class='dropzone span5 center',
                HTML("<p>Drag and drop photos and video here</p><p class='big'>+</p><p>Or click to add using the file browser</p>")
                )
            )
        )

但这是在关键字arg - &gt;之后给出一个SyntaxError:非关键字arg;指向HTML字段的行。 Div中包含HTML有什么问题吗?如何翻译给定的HTML?

1 个答案:

答案 0 :(得分:4)

错误信息很清楚,不是吗?

例如,你的内部块应该看起来像这样(**args* fist, then ***kwargs*):

Div(
    HTML("<p>Drag and drop photos and video here</p><p class='big'>+</p><p>Or click to add using the file browser</p>"),
    css_id='image-drop',
    css_class='dropzone span5 center'
)