Django 1.6 + AngularJS v1.2.6 + Amazon Aws
I have a problem integrating my existing django app with angular, I have installed Amazon AWS with Boto for static files, but when using AngularJs I get this error:
Blocked loading resource from url not allowed by $sceDelegate policy. URL:
So, I researched and tried to do this:
$sceDelegateProvider.resourceUrlWhitelist(['self',djangoStaticURL]);
In my module config, but dopesn't seems to work, so I tried:
templateUrl: $sceProvider.trustAsResourceUrl(djangoStaticURL + 'app/views/main.html'),
And get $ sce no provider defined, this is my complete module:
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: '/'
});
});
So this is a bad idea? should i do all the routing from django? or is there something no-hmm?
source to share
I finally solved it by editing my AWS CORS config like this:
Select your bucket where your static files are Select Properties Select "Edit CORS Configuration"
Paste something like this
<?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>
More information: http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
source to share