i am trying to fill a form with data via ajax request. The is my attempt so far:
view.py:
def ajaxGetData(request):
pnr=int(request.GET.get('pnr',None))
instance=User.objects.get(pnr=pnr)
form=User_Form(instance=instance,prefix="Userdata")
return HttpResponse(form.as_p())
Ajax Code:
$.ajax({
url: '{%url 'ajaxGetData'%}',
type: "get",
data: {
'pnr': pnr,
},
success: function (data) {
if (data) {
$('#Userdata-Content').html(data);
}
}
});
It does work, but the form is not rendered with crispy-forms. Is there some code like
return HttpResponse(form.as_crispy())
That would return a crispy form?
PS: I am quite new to Django and developing websites in general. I want to do a website where you can select a user from a list at the side of the page and then edit a whole bunch of data about him. From what i read doing a one-page-solution was the way to go for that. Would be quite thankful if someone can give me a hint if this is the right way to go about it.
Greetings!