python+django+js实现搜索框有值显示搜索结果,无值隐藏搜索结果

前端:

{% if msg %}

{{ msg }}

{% else %}
IP address PowerOn PowerOff
{{ IP_name }} PowerOn Restart
{% endif %}

 JS:

后端:

views.py

def searchresult(request):
    ip_address = request.GET.get('searchbar')
    opmessage = OP.objects.filter(ip_op = ip_address)
    vmmessage = VM.objects.filter(ip_vm = ip_address)
    if opmessage:
        ip_name = opmessage[0].ip_openstack
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })
    elif vmmessage:
        ip_name = vmmessage[0].ip_vmware
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })
    
def poweron(request,id)
    ip_address = request.GET.get('searchbar')
    opmessage = OP.objects.filter(ip_op = ip_address)
    vmmessage = VM.objects.filter(ip_vm = ip_address)
    if opmessage:
        ip_name = opmessage[0].ip_openstack
//执行开机命令
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })
    elif vmmessage:
        ip_name = vmmessage[0].ip_vmware
/执行开机命令
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })
def restart(request,id)
    ip_address = request.GET.get('searchbar')
    opmessage = OP.objects.filter(ip_op = ip_address)
    vmmessage = VM.objects.filter(ip_vm = ip_address)
    if opmessage:
        ip_name = opmessage[0].ip_openstack
//执行开机命令
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })
    elif vmmessage:
        ip_name = vmmessage[0].ip_vmware
/执行开机命令
        return render(request,"search.html",{
        "ip_address":ip_address,
        "ip_name":ip_name,
    })

 urls.py

url(r'searchform/$',searchresult)
url(r'searchform/poweron/(?P.*)/$',poweron)
url(r'searchform/restart/(?P.*)/$,restart)

 

你可能感兴趣的:(python+django+js实现搜索框有值显示搜索结果,无值隐藏搜索结果)