【发布时间】: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