i have following html file
<html> <head> {% load staticfiles %} <script type="text/javascript" src="{% static "app.js" %}"/></script> <title>flapper news</title> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> </head> {% verbatim foo %} <body ng-app="flappernews" ng-controller="mainctrl"> <div> <div ng-repeat="post in posts | orderby:'-upvotes'"> <span ng-click="incrementupvotes(post)">^</span> <a ng-show="post.link" href="{{post.link}}"> {{post.title}} </a> <span ng-hide="post.link"> {{post.title}} </span> - upvotes: {{post.upvotes}} </div> <form ng-submit="addpost()"> <input type="text" placeholder="title" ng-model="title"></input> <br> <input type="text" placeholder="link" ng-model="link"></input> <br> <button type="submit">post</button> </form> </div> </body> {% endverbatim foo %} </html> and angularjs file
'use strict' angular.module('flappernews', ['ngroute']) .controller('mainctrl', [ '$scope', function($scope){ $scope.test = 'hello world!'; $scope.posts = []; $scope.addpost = function(){ if($scope.title === '') { return; } $scope.posts.push({ title: $scope.title, link: $scope.link, upvotes: 0 }); $scope.title = ''; $scope.link = ''; }; $scope.incrementupvotes = function(post) { post.upvotes += 1; }; }]); the template located in mysite/templates , angular file located in mysite/static. when have @ development server receive following output when requesting page:
[10/jul/2015 09:23:09]"get /guides/ http/1.1" 200 861 [10/jul/2015 09:23:09]"get /static/app.js http/1.1" 404 1632 and when have @ developer console firefox receive error: [$injector:modulerr]. guys know why usage of app.js not working?
edit: static files in settings.py
static_url = '/static/' static_root = '/home/ubuntu/mysite/static/'
probably should set staticfiles_dirs in project settings. should trick:
staticfiles_dirs = ( os.path.join(base_dir, 'static'), ) it not enough set static_url (this url serving static files) , static_root (this location on server/system application store static files when run manage.py collectstatic).
by default django searches static files using appdirectoriesfinder (which searches static files in app directories) , filesystemfinder (which searches directories in staticfiles_dirs)
if static file settings still not clear, take @ documentation.
Comments
Post a Comment