[Fixed]-Django working with Angular.js static file

1πŸ‘

βœ…

I found some issues with your app

1. miss using double quote in script tag inside index_production.html. You need to use single quote between two double quote.

There is many places in your code miss using the double quote, please double check that. You can change your code this:

//             +--------------------------------+---- use single quote instead
//             v                                v
src="{% static '/node_modules/angular/angular.js' %}"

2. Use absolute path instead of relpath

angular.module('app').component('myComponent', {
    templateUrl: "/static/js/app.template.html", // <---- add '/' before static
    controller: ['$http', appController],
});

3. Move all your static files under β€˜src’

src
|---facebooklotto
|---lotto
|---static
|---db.sqlite3
|---manage.py

And change your static file setting like this:

STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

After making the changes above, I can run your webapp. Hope it would help…

πŸ‘€Enix

Leave a comment