Conversation
…g to VM. also, need to add error checking
|
Will, Check out the source of the canonical version of the app and the remainder of the slides from last week. POST forms in django require a csrf token in order to successfully submit. Django supplies a template tag that takes care of this: There is a reference to it in the slides, and it is used in my canonical version of the djangor app here: c On Feb 18, 2013, at 6:39 PM, pwnee wrote:
Cris EwingPrincipal, Cris Ewing, Developer LLC |
|
So, I looked this over more carefully just now and I can see that you did have the {% csrf_token %} template tag in your form. As it turns out that was not the only problem, though. Here's what is going on. The view you built to render the list of the blog entries (which is also the view that contains the form for adding a new entry, and where the csrf_token template tag is used) is built like so: return HttpResponse(template.render(context))While this is a perfectly valid way to render a template back to an http response, it does not include a I've re-written the view as follows: def blog_index(request):
latest_blog_posts = BlogPost.objects.order_by('pub_date')
context = Context({
'latest_blog_posts': latest_blog_posts,
})
return render_to_response('blog.html',
context,
context_instance=RequestContext(request))This will render a form in the blog.html template that does include the csrf token, and then when you submit it you'll start hitting the errors in your add_entry view. An even more up-to-date way of doing this same thing would be to use the def blog_index(request):
latest_blog_posts = BlogPost.objects.order_by('pub_date')
context = Context({
'latest_blog_posts': latest_blog_posts,
})
return render('blog.html', context)Hope this gets you un-stuck Cris |
Cris,
I'm submitting my attempt to get the blog up and running, but I've only been able to enter an entry manually via the shell. I had some difficulties getting POSTs to go through due to CSRF issues (see README). I imagine there's a better easier way to get this up and running hopefully I can make some updates to this and get it up and running eventually.
--Will