Monday, May 2, 2016

Re: Trying to make a POST call to a Django view

2016-05-02 18:11 GMT+02:00 ludovic coues <couesl@gmail.com>:
> I would use the browser developer tools to look at what JQuery is
> sending to django in the submit event.

http://dpaste.com/2MQTNZP

I do not see anything wrong there...

Any ideas?
Thank you

>
> 2016-05-02 18:01 GMT+02:00 carloratm <carlo.ratm@gmail.com>:
>> hello everyone,
>> I am a frontend developer studying Django, so please forgive my noobish
>> question...
>> I am trying to make a simple ajax call working.
>>
>> I have a form in a template. I would like to use that form to save an object
>> into the database (asynchronously).
>> On form submit event:
>> * I prevent regular action
>> * I serialize form data in a JSON
>> * I pass that object to a view using a jquery POST
>> * The view receive the JSON data
>> * The view use the request.POST data to save an object into the database.
>> * The view returns a message.
>>
>> Is that flow straightforward, or am I completely missing the goal?
>>
>> Now some code and the error I got.
>>
>> The relevant part of template:
>>
>> http://dpaste.com/3Z7TRPM
>>
>>
>> And this is the error I got:
>>
>> http://dpaste.com/3FYMGYG
>>
>> I noticed that in the view the request.POST is *empty*!
>> That is wrong, I suppose.
>>
>> I am surely missing something.
>> Any help is really appreciated.
>>
>> Thank you in advance,
>> carlo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/44f6da2a-c677-4485-99f2-eec20f8dfe0f%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/pRkBho_TZrQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTb4q_-OwNX%2BMWbp2DQrRB0-gdSv5-rD-h31GYrSWHXwew%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Carlo Ascani | www.carlorat.me
carloratm@freenode

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABVJJr-1NsiFcCU%2B-jsT9rVzDoZcesG18yt3Usz0LDXT3zj0YQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment