Philipl
Philipl

Reputation: 415

Django working with Angular.js static file

I am using Angular as my front end and Django as back end.

What I am facing is my server load the static file really slowly.Although,when I ran the server,the html shows the static file exist, but when I click on the url, it just keep load the file and eventually crashed.This is the GitHub link:https://github.com/Honesty1997/my-lotto-game.git

Hope you can help me find the problem!I am sure the django static file settings are all right!

Upvotes: 0

Views: 467

Answers (1)

Enix
Enix

Reputation: 4579

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...

Upvotes: 1

Related Questions