S
S
Sviat282018-11-22 21:52:55
Debian
Sviat28, 2018-11-22 21:52:55

How to pass variables to Django form via jQuery?

have a django form

class Name(forms.ModelForm):
  
    class Meta:
        model = Name
        fields = ('name', 'surname')


and there are variables that I created in jQuery

function save() {
     var name  = 'Monty';
     var surname  = 'Python';
}


I want to make a post request, and save these variables in the appropriate form fields, but I don't know how to make a post request in jquery and pass it correctly to the django form, usually when working with forms, we output them to the template, enter the data, click the button, and save, how to make this move, through the jQuery function?
def name(request):
  if request.method == "POST":
    form = Name(request.POST, request.FILES)
    if form.is_valid():
      name.save()
  else:
    print ("Произошла какая-то хрень")
    form = NameForm(request.POST)
    return render(request, 'site/name.html', {'form': form})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grims, 2016-01-17
@grims

It's so hard to say what's wrong with you, you need to analyze the output of commands.
[email protected]:~# lspci
[email protected]:~# lsmod | grep rtl
[email protected]:~# find /lib/modules -type f -name "rtl81"
Also see this , it might help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question