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

Mar*_*ark 2 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>
Run Code Online (Sandbox Code Playgroud)

我将如何包含标签和

标签?我试过这个:

    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>")
                )
            )
        )
Run Code Online (Sandbox Code Playgroud)

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

ari*_*rie 5

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

因此,例如您的内部块应该看起来像这样(**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'
)
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,但不,这个消息对我来说不是很清楚。无需在回复中讽刺,这对学习社区不利。 (3认同)
  • 对不起,我真的不是故意粗鲁的。我仍然坚持错误消息给出了一个明确的指向错误根源的指针`SyntaxError: non-keyword arg after keyword arg`。因此,如果您将错误消息变成一个问题并询问 _Where 在有问题的代码块中是否有非关键字参数跟随一个参数?_ 您几乎就在那里。至少这就是我所做的。 (2认同)