B
B
Black back2020-04-13 14:42:02
Django
Black back, 2020-04-13 14:42:02

Why is the form submission not saved to the database?

'dont save' fires

def House(request):
    if request.method == 'POST':
        form = Hous(request.POST, request.FILES)
        if form.is_valid():
            print("is valid")
            form.save()
            redirect('/')
        else:
            return HttpResponse('dont save')
    else:
        form = Hous()
    return render(request, 'front.html', {'form':form})



forms.py:

from django import forms
from .models import Hous


class Hous(forms.ModelForm):
    class Meta:
        model = Hous
        fields ='__all__'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-04-13
@bekss

The form is invalid, replace with and see the error. Shl for the same name of the model and form, you have to kick for a long time. HttpResponse('dont save')render(request, 'front.html', {'form':form})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question