2014-10-13 45 views
0

我是Django的新手,並且想要將AngularJS與Django集成。 Djangular已安裝並可以使用。在Djangon中使用AngularJS指令

基本目錄結構如下:

mysite/app/Templates/app/index.html

mysite/app/Templates/app/directives/item-detail.html

index.htmlurl.py通過url(r'^$', views.index, name='index'),參照,並在views.pyindex()返回

return render(
    request, 
    'app/index.html', 
    { 
     'somevar': "some variables from index()" 
    } 
) 

小號○當在我定義了一個directive<item-detail>使用

app.directive('itemDetail', function(){ 
    restrict: 'E', 
    templateUrl: '' 
}) 

我不知道要放在什麼templateUrl(或應該有其他配置)? templateUrl: "directives/item-detail.html"給出了404錯誤; template: "<h1>This is a template</h1>"工作正常。

回答

0

您應該將Angular模板視爲靜態文件。他們不需要被Django解析,而且你也不想爲它們創建url。把它們放在靜態目錄中,並通過普通的靜態路徑引用它們。