Lars
Lars

Reputation: 1270

|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.

Upvotes: 0

Views: 88

Answers (1)

michjnich
michjnich

Reputation: 3385

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

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

Upvotes: 1

Related Questions