【问题标题】:How can I able to handle both GET and POST requests in views.py in python vue js?如何在 python vue js 中处理 views.py 中的 GET 和 POST 请求?
【发布时间】:2018-05-06 02:28:38
【问题描述】:

我的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: 意外缩进

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

【问题讨论】:

    标签: javascript python django vue.js


    【解决方案1】:
    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)
    

    【讨论】:

    • 可能还有其他方法,例如“PUT”,因此在其他方法中为 GET 提供功能是不行的。
    • 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, } 返回渲染(请求,“searchnew.html”,na)
    • 我试过这个..但得到错误为 IndentationError: unexpected indent
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    • 2019-02-02
    • 1970-01-01
    • 2013-03-03
    • 2016-09-20
    • 1970-01-01
    相关资源
    最近更新 更多