Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class OperationCreate(CreateView):
- model = Operation
- form_class = OperationForm
- success_url = reverse_lazy('manage_operations')
- def form_valid(self, form):
- (...)
- form.save()
- return JsonResponse({'result': 'success'})
- def form_invalid(self, form):
- form.save()
- return JsonResponse({'result': 'error'})
- function postForm(url, form_selector) {
- var form = $(form_selector);
- var csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value')
- form.submit(function () {
- $.ajax({
- headers: { 'X-CSRFToken': csrf_token },
- type: 'POST',
- url: url,
- data: form.serialize()
- });
- });
- };
Add Comment
Please, Sign In to add comment