Answer the question
In order to leave comments, you need to log in
Why is an empty set of data added to the database when the page is opened?
When the page is opened normally, for some reason a post request is sent and json with null values is added to the database.
Where did the bug creep in and what's wrong?
Thank you!
def add_car(request):
""" Lets user add car card """
if request.POST:
data = request.POST
car_dict = dict()
car_dict['model'] = data.get('model')
car_dict['brand'] = data.get('brand')
car_dict['year'] = data.get('year')
car_dict['vin'] = data.get('vin')
json_data = json.dumps(car_dict)
MyCar.objects.create(car=json_data)
return render(request, 'car_adding_form.html', locals())
$(document).ready(function(){
$("#add_car").click(function(e){
e.preventDefault();
var extraForm = document.createElement('DIV');
$(extraForm).attr("data-is-sent", 0);
...
...
...
$.ajax({
type: "POST",
data: data,
cache: true,
});
$("[data-is-sent='0']").attr("data-is-sent", 1);
});
});
{"vin": null, "brand": null, "year": null, "model": null}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question