zoukankan      html  css  js  c++  java
  • 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"ControllerstaticReport")
                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"ControllerstaticReport\{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})
  • 相关阅读:
    leetcode_268.missing number
    leetcode_41. First Missing Positive_cyclic swapping
    cyclic swapping algorithm
    leetcode_919. Complete Binary Tree Inserter_完全二叉树插入
    前端的图片隐写术
    C#读取串口数据实现无线手柄操作ROV
    通过android传感器控制ROV云台转动
    C#实现的简易多人聊天室
    ARM Cortex M3指令集
    ODbgscript 1.82.x Document
  • 原文地址:https://www.cnblogs.com/ShineLeem/p/11325764.html
Copyright © 2011-2022 走看看