django前端查看与新增在同一个views方法中实现

1,前端样式:

django前端查看与新增在同一个views方法中实现_第1张图片

2.html代码

{% load staticfiles %}



后台代码:

@login_required(login_url='/account/login/')
@csrf_exempt
def article_column(request):
    '''
    查看和更新article_column
    :param request:
    :return:
    '''
    if request.method == "GET":
        columns = ArticleColumn.objects.filter(user=request.user)
        column_form = ArticleColumnForm()
        return render(request,'article/column/article_column.html',{'columns':columns,'column_form':column_form})

    if request.method == "POST":
        column_name = request.POST['column']
        columns = ArticleColumn.objects.filter(user=request.user,column = column_name)
        if columns :
            return HttpResponse(0)
        else:
            ArticleColumn.objects.create(user=request.user,column=column_name)
            return HttpResponse(1)

你可能感兴趣的:(django)