如何在python vue js中的views.py中处理GET和POST请求?

时间:2017-11-22 11:09:20

标签: javascript python django vue.js

我的views.py是

def searchnew(request):
if request.method == 'POST':
    name = request.POST.get('name')
    loc = request.POST.get('location')
    d = {
    'name': name,
    'loc' : loc,

    }
    return render(request,"searchnew.html",d)
else:
     name = request.GET.get('name')
      na = {
    'name': name,

    }
     return render(request,"searchnew.html",na)

我有GET请求和其他POST请求。在这种情况下,我怎样才能处理GET请求?

这是我的GET请求

<a v-bind:href="'searchnew/?name='+post.name">{{post.name}}</a>

我收到错误了 IndentationError:意外缩进

我怎样才能传递这个名字?

1 个答案:

答案 0 :(得分:2)

def searchnew(request):
    if request.method == 'POST':
        name = request.POST.get('name')
        loc = request.POST.get('location')
        d = {
            'name': name,
            'loc': loc,

        }
        return render(request, "searchnew.html", d)
    else:
    # do the thing you want to do in GET method
        name = request.GET.get('name')
        na = {
           'name': name,
        }
        return render(request,"searchnew.html",na)