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__
.
- Template for reusable Django app is not rendering
- Security using Django 1.10 + AJAX without any HTML form
- How to do unit testing for this?
- Django display filefield in Template
- Form not Rendered in Django
Source:stackexchange.com