【问题标题】:|as_crispy_field got passed an invalid or inexistent field in CharField|as_crispy_field 在 CharField 中传递了一个无效或不存在的字段
【发布时间】:2021-01-27 04:21:57
【问题描述】:

我正在构建一个 BlogApp,在尝试设置表单样式时出现此错误。 :-

|as_crispy_field 传递了一个无效或不存在的字段

edit.html

{% load crispy_forms_tags %}

{% block content %}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="container">
    <form method="post" enctype="multipart/form-data">
        {% csrf_token %}
        <table>
        {{ allowance_form|as_crispy_field }}
        </table>
        <button type="submit">Save Changes</button>
    </form>
</div>

{% endblock content %}

views.py

def edit_allowance(request,user_id):
    if request.method == 'POST':
        allowance_form  = ProfilePhotoAllowForm(request.POST, request.FILES, instance=request.user.profile)

        if allowance_form.is_valid():
            custom_form = allowance_form.save(False)
            custom_form.save()
            return redirect('profiles',user_id=user_id)

    else:
        allowance_form = ProfilePhotoAllowForm(instance=request.user.profile)

    context = {'allowance_form':allowance_form}
    return render(request, 'edit.html', context)

每当我运行该页面时,它都会向我显示 |as_crispy_field got passed an invalid or inexistent field 错误。

我不知道本准则有什么问题。我检查了 StackOverFlow 上的所有回答,但他们对此没有帮助。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: python html django django-views django-templates


    【解决方案1】:

    allowance_form 不是字段。这是整个表格。

    改用{{ allowance_form|crispy }},应该没问题。

    【讨论】:

      猜你喜欢
      • 2020-03-03
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 2019-11-20
      • 2021-08-31
      • 2016-07-17
      • 1970-01-01
      相关资源
      最近更新 更多