def view_post(request, slug): post = get_object_or_404(Item, slug=slug) form = CommentForm(request.POST or None) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect(request.path) return render_to_response('wunderlist/page.html', { 'post': post, 'form': form, }, context_instance=RequestContext(request))
def page(request, category_name_slug, page_name_slug): # Create a context dictionary which we can pass to the template rendering engine. context_dict = {} try: # Can we find a category name slug with the given name? # If we can't, the .get() method raises a DoesNotExist exception. # So the .get() method returns one model instance or raises an exception. page = Item.objects.get(title=page_name_slug) #if request.method=='POST': #p.category = request.POST.get('category',"") # page.title = request.POST.get('title'," ") # page.subtask = request.POST.get('subtask'," ") # page.notes = request.POST.get('notes'," ") #page.dueDate = request.POST.get('dueDate',"") #page.tags = request.POST.get('tags'," ") #print "finally: ",request.POST.get('tags'," ") #page.taskDone = request.POST.get('taskDone'," ") context_dict['page'] = page context_dict['tags'] = Tag.objects.all() post = get_object_or_404(Item, title=page_name_slug) form = CommentForm(request.POST or None) context_dict['post'] = post context_dict['form'] = form if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect(request.path) except Category.DoesNotExist: # We get here if we didn't find the specified category. # Don't do anything - the template displays the "no category" message for us. pass # Go render the response and return it to the client. return render(request, 'wunderlist/page.html', context_dict)