Django前后端关联

在urls.py中建立映射关系,index/是你model代码模块中的函数,也可以是你在界面上制定的form表单中的action,这样就可以建立前后端的联系

 <form action="/index/" method="post" class="form-horizontal" onsubmit="return check()">
{% csrf_token %}

 

urlpatterns = [
    path('admin/', admin.site.urls),
    path('platform/', views.platform),  # 第一个参数是模块函数的函数名,具体界面这里不负责,卸载模块的返回中
    path('index/', projectcode.run, name='index'),
    # path('login/', projectcode.login, name='login'),
    path('report/', projectcode.report),
]
def report(request):
    """
    重定向测试报告
    :param request:
    :return:
    """
    reportlist, htmlname = getreport()
    if request.method == 'POST':
        reportname = request.POST.get("reportname")
        delname = request.POST.get("delname")
        if delname != None:
            path = os.path.join(os.getcwd(), f"Controller\static\Report")
            file = path + f'\\{delname}'
            if (os.path.exists(file)):
                shutil.rmtree(file)
            reportlist = getreport()
        if reportname == None:
            reporthtml = ''
        else:
            reporthtml = f'.././static/Report/{reportname}/{reportname}.html'
    else:
        reporthtml = ''
    reportlist, htmlname = getreport()
    htmlstate = copy.deepcopy(reportlist) # copy一个新的字典
    for i in htmlname:
        file_Path = os.path.join(os.getcwd(), f"Controller\static\Report\\{i}\\{i}.html")
        print(file_Path)
        if os.path.exists(file_Path):
            key = i.split("_")[1]
            htmlstate[key] = '1'
        else:
            key = i.split("_")[1]
            htmlstate[key] = '0'


    return render(request, "public.html", {'reporthtml': reporthtml, 'report': reportlist, 'htmlstate': htmlstate})

 

posted @ 2019-08-09 10:49  ShineLeem  阅读(379)  评论(0编辑  收藏  举报