[Fixed]-Django form is invalid, but no error messages

1👍

Instead of sending an HttpResponse, you need to render the html with the form if the form is invalid.

if form.is_valid():
    # Do your operations on the data here
    ...
    return render(request, 'no_entiendo.html', {'colors': colors, })
else:
    return render(request, 'Disenador/sku_builder.html', {'form': form,})

Also if you’re using model choice fields, the ideal place to define your queryset is in your form’s __init__ method

def __init__(self, *args, **kwargs):
    user = kwargs.pop('user')
    self.fields['base_item'].queryset = BaseItem.objects.filter(designer=user)
    # define more querysets here as you require
    ...
    super(SkuForm, self).__init__(*args, **kwargs)

You can change the queryset in view. But that as far as I understand is a way to override whatever you have set in your forms. It should normally be set in __init__.

0👍

try to render {{form.errors}} in your template

👤rsb

Leave a comment