[django] 양식 제출과 POST 직접 제출의 차이점

1222 단어 pythonDjango
def article_tag_rename(request):
    # edit
    # data:{"tag_id":tag_id, "tag_name":new_name},
    '''
     #  1: form = xxxForm(data=request.POST)          
    #      ,   POST        model      

    #  2:   request.POST['id']  request.POST['tag']    POST      
    #       POST   model      
    # id = request.POST['id']
    # tag =request.POST['tag']   
    '''
    
    # Form       POST  
    #       http  POST          Form          ,       data=request.POST
    rename_tag = ArticleTag.objects.get(id=request.POST['id'])
    rename_tag_form = ArticleTagForm(data=request.POST)
    if rename_tag_form.is_valid():
        cd = rename_tag_form.cleaned_data
        try:
            rename_tag.tag = cd["tag"]
            rename_tag.save()
            return HttpResponse("1")
        except:
            return HttpResponse("    ")
    else:
        #        :
        is_echo = ArticleTag.objects.filter(tag=request.POST['tag'])
        if is_echo:
            return HttpResponse("     !")
        else:
            return HttpResponse("    !")

좋은 웹페이지 즐겨찾기