2017-05-19 25 views
0

我有GAE和Angular關於在HTML模板上動態更新數據的問題。 我想要的是當新用戶插入系統時,它必須自動顯示在頁面上,該頁面列出了系統的所有用戶。 我不知道如何。我閱讀了Angular,它似乎是一個在HTML網頁上動態更新數據的好框架。 我使用JINJA獲取頁面,並通過查詢存儲所有用戶的NDB數據存儲填充模板。 這是web應用程序處理器,其「處理頁面」的代碼:GAE和Angular:如何更新HTML JINJA模板的數據

class TestA(BaseHandler): 
    def get(self): 
    template = JINJA_ENVIRONMENT.get_template('templates/Ang2.html') 
    Users=datastore._retrieve_all_user() 
    w = self.response.write 
    w(template.render({'Users': Users})) 

當我添加一個新用戶的所有用戶的頁面顯示,同時在另一個選項卡中的更新沒有顯示,但如果我手動刷新頁面顯示新用戶。

所以,我想要的是以自動的方式獲得相同的結果。 重點是我想定期刷新HTML頁面,以顯示最終的新用戶。

所以我專注於Angular,特別是在$ interval和$ route.reload()上,但是我試圖做出一些有用的東西,但我沒有任何東西。

這就是模板的代碼:

<!doctype html> 
<html ng-app="demoApp"> 
<head> 
    <title>Hello from a template page!</title> 
    <link rel="stylesheet" type="text/css" href="/css/helloworld.css"> 
</head> 
<body> 
    <h1>Hello world HTML template.</h1> 
    <div data-ng-controller="MyController"> 
    <h3>Elenco utenti:</h3> 
    <ul> 
    {% for User in Users %} 
<li><b>{{User.username}}</b>: {{User.email}} </li> 
{% endfor %} 
    </ul> 
</div> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> 
</script>  
<script> 
var demoApp = angular.module("demoApp", []); 
myapp.controller("MyController", function($scope, $interval){ 

$interval(callAtInterval, 5000); 


}); 

function callAtInterval($route) { 
$route.reload(); 

} 
</script> 

</body> 

任何提示,那怎麼辦? PS:我知道這個解決方案不夠高雅,但是我選擇了這個解決方案,因爲我需要知道如何去做,因爲它對於我的web應用程序的功能開發的後續步驟很有用

+0

什麼是錯誤您收到? –

+0

http://stackoverflow.com/questions/30362950/is-it-possible-to-use-angular-with-the-jinja2-template-engine –

回答