简体   繁体   English

在网页[Django] [Python]上显示使用json2html生成的html?

[英]Show html generated by using json2html at webpage [Django] [Python]?

Following is my code in view: 以下是我的代码:

 RESULTS= {}
 for k in RESULTS_LIST[0].iterkeys():
   RESULTS[k] = list(results[k] for results in RESULTS_LIST)
 RESULTS.pop('_id',None)
 html_table =  json2html.convert(json=RESULTS)
 return render(request,'homepage.html',{'html_table':html_table})

here I am arranging a data fetched from Mongo Db in a JSON named as RESULTS and by using JSON2HTML package, it is successfully generated html table for data given in JSON. 在这里,我正在安装一个名为RESULTS的JSON中从Mongo Db获取的数据,并使用JSON2HTML包,它成功生成了用于JSON中给出的数据的html表。 To embedd the html table code in a blank division at html page, I am doing: 要在html页面的空白部门中嵌入​​html表格代码,我正在做:

<div>{{html_table}}</div>

But it failed to display the table on page. 但它无法在页面上显示该表。 I have tried numerous ways to make it but didn't succeed. 我尝试了很多方法,但没有成功。 Please help me to resolve this issue. 请帮我解决这个问题。 if any relevant example, you have done before , then please guide me in a right direction. 如果有任何相关的例子,你以前做过,那么请指导我正确的方向。

JS code is: JS代码是:

angular.module("homeapp",[])
.controller("homecontroller",['$http','$scope',function($http,$scope){
    $scope.search= {
        'keyword': null,
        'option': null,
        'startDate':null,
        'lastDate': null
    };
    $scope.search_info=function(){
        var search_req = {
            url:'/home',
            method:'POST',
            data:$scope.search
        }
        $http(search_req) //in case I dont want any response back or
        $http(search_req).success(function(response){     
            window.alert(response)
         }) //in case I need to check response
    }

}]);

I have got solution to this problem in an easy way via using js, which is given below and it worked. 我通过使用js以简单的方式解决了这个问题,下面给出了它并且它有效。

    $http(search_req).success(function(response){     
        angular.element(".search_results").append(response);
     })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM