예제 #1
0
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/')
예제 #2
0
파일: views.py 프로젝트: treyham91/blogsite
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})
예제 #3
0
파일: views.py 프로젝트: wtzhu13/bolg
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/')
예제 #4
0
파일: views.py 프로젝트: fjrti/snippets
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/')
예제 #5
0
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/')
예제 #7
0
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/')
예제 #9
0
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')
예제 #10
0
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/')
예제 #11
0
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')