Hi,
I have a BSModalFormView with a BSModalForm for the form.
When I submit the form it double posts.
Since I'm deleting the initial result, when it calls the post the second time returns 404.
After a bit of research I've found Stack overflow post which seems to be the same.
The top answer says the package was updated and that fixes the problem, however it is still doing it for me.
When I've tried to print the self.request.is_ajax() I get the 'WSGIRequest' object has no attribute 'is_ajax' which brought me to this call was depreciated in Django 3.1.
Which from the depreciation notes lead me to:
def form_valid(self, form: Any) -> HttpResponse:
valid = super().form_valid(form)
if not valid:
return valid
if self.request.headers.get('x-requested-with'): # Ajax check. Will skip on first call
return valid
# rest of validation stuff here.
# delete initial model here.
return valid
The check for the header will not save the form on the first call only on the second.
This doesn't seem a very pythonic answer to me.
Hi,
I have a
BSModalFormViewwith aBSModalFormfor the form.When I submit the form it double posts.
Since I'm deleting the initial result, when it calls the post the second time returns 404.
After a bit of research I've found Stack overflow post which seems to be the same.
The top answer says the package was updated and that fixes the problem, however it is still doing it for me.
When I've tried to print the
self.request.is_ajax()I get the'WSGIRequest' object has no attribute 'is_ajax'which brought me to this call was depreciated in Django 3.1.Which from the depreciation notes lead me to:
The check for the header will not save the form on the first call only on the second.
This doesn't seem a very pythonic answer to me.