示例#1
0
文件: views.py 项目: zako16/gag
def create_post(request):
    if request.user.is_staff:
        form = PostsForm(request.POST or None, request.FILES or None)
        if form.is_valid():
            form.save()
            return redirect('/index')
        return render(request, 'posts/create_post.html', {'form': form})
    return redirect('/error/')
示例#2
0
文件: views.py 项目: zako16/gag
def edit_post(request, post_id):
    if request.user.is_staff:
        post = Posts.objects.get(id=post_id)
        form = PostsForm(request.POST or None, request.FILES or None, instance=post)
        if form.is_valid():
            form.save()
            return redirect('/index')
        return render(request, 'posts/create_post.html', {'form': form})
    return redirect('/error/')