簡體   English   中英

在網頁[Django] [Python]上顯示使用json2html生成的html?

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

以下是我的代碼:

 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})

在這里,我正在安裝一個名為RESULTS的JSON中從Mongo Db獲取的數據,並使用JSON2HTML包,它成功生成了用於JSON中給出的數據的html表。 要在html頁面的空白部門中嵌入​​html表格代碼,我正在做:

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

但它無法在頁面上顯示該表。 我嘗試了很多方法,但沒有成功。 請幫我解決這個問題。 如果有任何相關的例子,你以前做過,那么請指導我正確的方向。

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
    }

}]);

我通過使用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