2014-09-04 99 views
3

我有我的整合現有的Django應用程序有棱有角,我已經設置好的亞馬遜AWS與寶途的靜態文件有問題,但使用AngularJs當我得到這個錯誤:的Django 1.6 + AngularJS V1.2.6 +亞馬遜AWS

Blocked loading resource from url not allowed by $sceDelegate policy. URL:

所以我調查,並試圖做到這一點:

$sceDelegateProvider.resourceUrlWhitelist(['self',djangoStaticURL]); 

在我的模塊配置,但dopesn't似乎工作,所以我嘗試:

templateUrl: $sceProvider.trustAsResourceUrl(djangoStaticURL + 'app/views/main.html'), 

而且獲得未定義$ SCE供應商,這是我的完整模塊:

angular.module('portfolioApp', [ 
    'ngCookies', 
    'ngResource', 
    'ngSanitize', 
    'ngRoute', 
    'portfolioApp.filters', 
]).config(function ($sce ,$routeProvider, $sceDelegateProvider) { 
    $sceDelegateProvider.resourceUrlWhitelist(['self',djangoStaticURL]); 
    $routeProvider 
    .when('/', { 
     templateUrl: $sce.trustAsResourceUrl(djangoStaticURL + 'app/views/main.html'), 
     //templateUrl: djangoStaticURL + 'app/views/main.html', 
     controller: 'MainCtrl' 
    }) 
    .otherwise({ 
     redirectTo: '/' 
    }); 
}); 

因此,這是一個壞主意?我應該從django做所有的路由嗎?或者有什麼我錯過了?

+0

你有沒有想過這個出來嗎? – Brendan 2014-10-20 15:35:50

+0

@Brendan其實是的,檢查我的回答 – afk 2014-10-20 15:52:15

回答

2

我終於解決了這個編輯AWS CORS配置是這樣的:

選擇您的桶,你的靜態文件 選擇屬性 選擇編輯CORS配置

粘貼這樣的事情

<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
    <CORSRule> 
     <AllowedOrigin>http://arlefreak.herokuapp.com/</AllowedOrigin> 
     <AllowedMethod>PUT</AllowedMethod> 
     <AllowedMethod>POST</AllowedMethod> 
     <AllowedMethod>DELETE</AllowedMethod> 
     <AllowedHeader>*</AllowedHeader> 
    </CORSRule> 
    <CORSRule> 
     <AllowedOrigin>http://*.arlefreak.com/</AllowedOrigin> 
     <AllowedMethod>PUT</AllowedMethod> 
     <AllowedMethod>POST</AllowedMethod> 
     <AllowedMethod>DELETE</AllowedMethod> 
     <AllowedHeader>*</AllowedHeader> 
    </CORSRule> 
    <CORSRule> 
     <AllowedOrigin>*</AllowedOrigin> 
     <AllowedMethod>GET</AllowedMethod> 
    </CORSRule> 
</CORSConfiguration> 

更多的信息在:http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

+0

這有幫助!感謝您發佈。 – Brendan 2014-10-20 21:57:02