def create_post(request): if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() return HttpResponseRedirect('/') else: form = PostForm() return render(request, 'post.html', {'form': form})
def home(req): tmpl_vars = { 'all_posts': Post.objects.reverse(), 'form': PostForm() } return render(req, 'talk/index.html', tmpl_vars)
def home(request): tmpl_vars = {'form': PostForm()} return render(request, 'talk/index.html', tmpl_vars)
def home(request): ctx = {'all_posts': Post.objects.reverse(), 'form': PostForm()} return render(request, 'talk/index.html', ctx)
def home(request, template_name): all_posts = Post.objects.reverse() form = PostForm() return render(request, template_name, locals())