【问题标题】:django.template.exceptions.TemplateSyntaxError: 'bootstrap_field' received some positional argument(s) after some keyword argument(s)django.template.exceptions.TemplateSyntaxError: \'bootstrap_field\' 在一些关键字参数之后收到了一些位置参数
【发布时间】:2022-11-25 03:45:39
【问题描述】:

我试图用引导字段和一些参数修改我的 django sign_in 模板,但我也做不到。

例外:

C:\Users\hp\Desktop\fastparcel\core\templates\sign_in.html, error at line 25

'bootstrap_field' received some positional argument(s) after some keyword argument(s)
{% bootstrap_field form.username show_lable=False placeholder ="Email" %}`

HTML

{% extends 'base.html' %}
{% load bootstrap4 %}

{% block content%}

<div class="container-fluid mt-5">
    <div class="justify-content-center">
        <div class="col-lg-4">
            <div class="card">
                <div class="card-body">
                    <h4 class="text-center text-uppercase mb-3">
                        <b>
                            {% if request.GET.next != '/courier/'%}
                            Customer
                            {% else %}
                            Courier
                            {% endif %}
                        </b>

                    </h4>
                    <form action="POST">
                        {% csrf_token %}
                        {% bootstrap_form_errors form %}
                        {% bootstrap_label "Email" %}
                        {% bootstrap_field form.username show_lable=False  placeholder ="Email" %}
                        {% bootstrap_field field form.password %}
                        <button class="btn btn-warning btn-block "> Sign in</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}

【问题讨论】:

  • 可能只是打错了,show_lable=False应该是show_label=False
  • 尝试但仍然是同样的错误
  • 尝试删除 {% bootstrap_field form.username show_lable=False placeholder ="Email" %} 中占位符后的空格,使其类似于 {% bootstrap_field form.username show_label=False placeholder="Email" %}
  • 别客气。当等号后面有空格时,Django 不会认为您传递的是关键字,而是认为这是一个位置参数,也就是说,其含义由其位置决定。所以 Django 将占位符作为位置参数,因为它们依赖于它们的位置,所以你总是把它们放在关键字参数之前。关键字参数,例如 key=value

标签: python html django bootstrap-4 backend


【解决方案1】:

谢谢@raphael 答案是 删除占位符后的空格

{% bootstrap_field form.username show_lable=False placeholder ="Email" %}

像是

{% bootstrap_field form.username show_label=False placeholder="Email" %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 2023-03-31
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2020-02-20
    相关资源
    最近更新 更多