def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = timezone.now() form.save() return HttpResponseRedirect('/blog/')
def blog_post_form(request): form = BlogPostForm() if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): form.save(commit=True) return render(request, 'post_success.html', {}) else: print('FORM ERROR') return render(request, 'blog_post_form.html', {'form': form})
def create_blog(request): """ 博客内容编辑提交类 :param request: :return: """ if request.method == 'POST': # 未使用django自带的表单模式 # try: # blog = BlogPost.objects.create( # title=request.POST.get('title'), # body=request.POST.get('body'), # timestamp=datetime.now(), # ) # print(blog) # except: # print("失败") # 使用form类创建 form = BlogPostForm(request.POST) if form.is_valid(): # 由于时间参数,所以save时不能执行 post = form.save(commit=False) post.timestamp = datetime.now() post.save() # 通过HttpResponseRedirect重定向到指定页面 return HttpResponseRedirect('/blog/')
def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() post.save() return HttpResponseRedirect('/blog/')
def blog_create(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() # 因为表单中不含 timestamp 所以必须手动生成 post.save() return HttpResponseRedirect('/blog/')
def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) # this returns a BlogPost object #uncomment next line if timestamp has default value #post.timestamp = datetime.now() post.save() # redirect to parent page return HttpResponseRedirect('/blog/')
def create_blogpost(request): if request.method == 'POST': # BlogPost(title=request.POST.get('title'), body=request.POST.get('body'), timestamp=datetime.now(),).save() form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() post.save() return redirect('/blog/')
def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) #this returns a BlogPost object #uncomment next line if timestamp has default value #post.timestamp = datetime.now() post.save() # redirect to parent page return HttpResponseRedirect('/blog/')
def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() post.save() # BlogPost( # title = request.POST.get('title'), # body = request.POST.get('body'), # timestamp = datetime.now() # ).save() return HttpResponseRedirect('/blog')
def create_blogpost(request): if request.method == 'POST': form = BlogPostForm(request.POST) #form=BlogPostForm(initial={'title':'1'} if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() _saveBody(post.body) _compileCpp() result = _computeResult("{}result.txt".format(cppPath)) post.body = "your score is " + str(result) post.save() return HttpResponseRedirect('/blog/')
def create_blogpost(request): if request.method == 'POST': # 检查POST请求 # 创建新的BlogPost项,获取表单数据,并用当前时间建立时间戳。 # BlogPost( # title=request.POST.get('title'), # body=request.POST.get('body'), # timestamp=datetime.now() # ).save() form = BlogPostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.timestamp = datetime.now() post.save() # 重定向会/blog return HttpResponseRedirect('/blog')