tag:blogger.com,1999:blog-6072463814914813547.post4245963110514356338..comments2023-06-22T05:09:08.890-07:00Comments on Django E-Commerce: Django and Ajax Form SubmissionsJim McGawhttp://www.blogger.com/profile/02849525770389840778noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-6072463814914813547.post-71634656154533187002012-11-28T12:39:26.418-08:002012-11-28T12:39:26.418-08:00I replaced this line:
slug = request.POST.get('...I replaced this line:<br />slug = request.POST.get('slug')<br />with<br />slug = request.POST.get('id_slug')<br />in views.py however the slug is always None! If I set the slug explicitly to an available product slug, everything that follows works perfectly! Why the 'id_slug' is not passed in the request.POST.. I made sure it is written correctly in the template! thx a lot!larahttps://www.blogger.com/profile/02077911059814674689noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-40825392604264116072012-04-17T14:27:04.760-07:002012-04-17T14:27:04.760-07:00More details were sent in a personal message.
I&#...More details were sent in a personal message.<br /><br />I'll post thr solution if we solve the problemredatesthttps://www.blogger.com/profile/16701779998950729086noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-47142243571445279002012-04-17T10:36:57.740-07:002012-04-17T10:36:57.740-07:00Hi redatest-
There's not a lot of detail to g...Hi redatest-<br /><br />There's not a lot of detail to go on here. So you added the {% csrf_token %} inside of the form element, but you're still getting an error? What kind of error are you seeing?<br /><br />Feel free to shoot me an email to get this sorted out: jim@django-ecommerce.com. Thanks!<br /><br />JimJim McGawhttps://www.blogger.com/profile/02849525770389840778noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-10660267157843436432012-04-16T16:34:33.402-07:002012-04-16T16:34:33.402-07:00First i'd like to thank you for the best tutri...First i'd like to thank you for the best tutrial on the net about Django .<br /><br />Beacause i am using the version 1.4a1 of django, i just want to know how to handle CSRF protection on jquery/ajax used in posting previews on products(mentioned on page 217).<br /><br />in other words i tried to modify the function addProductReview() in the file scripts.js as it is said in this tutorial:<br />https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it<br /><br />but i could not how to do it <br /><br />thanks in advanceredatesthttps://www.blogger.com/profile/16701779998950729086noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-50316684993451313972011-03-20T18:31:16.246-07:002011-03-20T18:31:16.246-07:00HI DF,
This should work with Django 1.0 without a...HI DF,<br /><br />This should work with Django 1.0 without any problem. The example in the book uses 1.1, but I don't see anything here that changed. For Django 1.2 and later, it might be necessary to add the {% csrf_token %} tag to the form to avoid the HTTP 403 Forbidden security warning, which is more likely to come up since the CSRF protection is enabled by default.Jim McGawhttps://www.blogger.com/profile/02849525770389840778noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-77358922458575646362011-03-20T16:22:13.662-07:002011-03-20T16:22:13.662-07:00What version of Django does this require? I'm...What version of Django does this require? I'm using 1.0.DFhttps://www.blogger.com/profile/10928712770628693547noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-54621160220135730552010-06-07T02:24:48.781-07:002010-06-07T02:24:48.781-07:00Hello Jim,
I am following you in the book and I w...Hello Jim,<br /><br />I am following you in the book and I would like to point to two typos I found in this post, so others will not spend hours finding what's wrong...<br /><br />First is in the view function.<br />This line<br />slug = request.POST.get('slug')<br />should be like this<br />slug = request.POST.get('id_slug')<br /><br />Second is in the function in script.js file.<br />This line<br />success: function(json){<br />should be like this<br />success: function(response){<br /><br />It took me a while to find what is going on here, I am very newbie......<br /><br />Anyway, thank you very much for a great tutorial!VodoTopoPlynhttps://www.blogger.com/profile/02441827377594737559noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-32340571304743231082010-05-03T16:45:50.317-07:002010-05-03T16:45:50.317-07:00Hi Miguel,
I do that quite often, and it's si...Hi Miguel,<br /><br />I do that quite often, and it's similar to the way you described. The way I like to do it is to return the form errors rendered as a UL element or return the bound form rendered as HTML with the errors.<br /><br />if request.is_ajax() and request.method == 'POST':<br /> form = MyForm(request.POST)<br /> if form.is_valid():<br /> pass # do something here - redirect(?)<br /> else:<br /> form_html = form.as_table()<br /> data = {'form_html': form_html}<br /> json = simplejson.dumps(data)<br /> return HttpResponse(json)<br /><br />Then, have jQuery update the DOM with the newly bound form data, which should contain the errors.<br /><br />Optionally, you might work this flow into the normal view function for the page, so that if the user has JavaScript disabled, the form submissions will still process correctly and render errors to the user.Jim McGawhttps://www.blogger.com/profile/02849525770389840778noreply@blogger.comtag:blogger.com,1999:blog-6072463814914813547.post-23746949267301284112010-04-26T06:58:02.523-07:002010-04-26T06:58:02.523-07:00Great post! very helpful indeed :D
I was wonderin...Great post! very helpful indeed :D<br /><br />I was wondering if you know any way to do DJango form validation within an ajax call to a view. <br /><br />I would like to do something like this:<br />if request.is_ajax():<br /> form.is_valid()<br /><br />And if there are errors return them so JQuery can parse and show them :D<br /><br />ThanksUnknownhttps://www.blogger.com/profile/09070024691003335351noreply@blogger.com