django - 如何在 Django Crispy Forms 中包含 HTML header 标签?

标签 django django-crispy-forms

我有以下 HTML 片段,我想将其转换为 django 脆皮形式:

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

但是这给出了一个 SyntaxError: non-keyword arg after keywords arg --> 指向包含 HTML 字段的行。 Div 中的 HTML 是否有问题?如何翻译给定的 HTML 片段?

最佳答案

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

例如,您的内部 block 可能应该如下所示( **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'
)

关于django - 如何在 Django Crispy Forms 中包含 HTML header 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14266887/

相关文章:

python - Django 调用 'id' 需要一个数字,但得到字符串

django 脆皮形式 内联表单

Django CrispyForms - 在单独的引导选项卡中渲染表单集的每种形式

python - 如何删除行 [DEBUG] pip.vcs : Registered VCS backend: *** from log file

django-crispy-forms - django-filter软件包的模板在哪里?

django - 导入错误: No module named bootstrap3

django - BooleanField 复选框无法使用 bootstrap 正确呈现出crispy_forms

django - 在网站中传递商家 key 和盐

mysql - 错误的字符串值 : '\xE0\xB9\x82\xE0\xB8\xA3...' for column 'text' at row 1

javascript - 如何删除ajax响应函数中的li元素