Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

python - |as_crispy_field got passed an invalid or inexistent field in CharField

I am building a BlogApp and while trying to styling the forms i got this error. :-

|as_crispy_field got passed an invalid or inexistent 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)

Whenever i run the page it keep showing me this |as_crispy_field got passed an invalid or inexistent field Error.

I don't know what's wrong in this Code. I checked all answered on StackOverFlow BUT they didn't help me in this.

Any help would be appreciated.

Thank You in Advance.

question from:https://stackoverflow.com/questions/65907981/as-crispy-field-got-passed-an-invalid-or-inexistent-field-in-charfield

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

allowance_form is not a field. It's the entire form.

Use {{ allowance_form|crispy }} instead, and it should be fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...