Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django rest-framework : can't get static files

When I use rest-framework in my localhost it works well :

enter image description here

But when I put my code to amazon EC2 and use supervisor open the port 8000 with wsgi.ini BUT it can't get CSS and JS files:

"NetworkError: 404 NOT FOUND - http://ec2-1-2-3-4.ap-northeast-1.compute.amazonaws.com:8000/static/rest_framework/css/bootstrap-tweaks.css"

my settings.py :

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    ("js", os.path.join(STATIC_ROOT,'js')),
    ("css", os.path.join(STATIC_ROOT,'css')),
    ("images", os.path.join(STATIC_ROOT,'images')),
    ("fonts", os.path.join(STATIC_ROOT,'fonts')),
)

Why would this happen?? Please help me! Thank you very much

like image 203
user2492364 Avatar asked Nov 19 '14 08:11

user2492364


People also ask

Can Django serve static files?

Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help you manage them.

Where is Django looking for static files?

Using the collectstatic command, Django looks for all static files in your apps and collects them wherever you told it to, i.e. the STATIC_ROOT . In our case, we are telling Django that when we run python manage.py collectstatic , gather all static files into a folder called staticfiles in our project root directory.

What is static files in Django?

Static Files such as Images, CSS or JS files are often loaded via a different app in production websites to avoid loading multiple stuff from the same server.


1 Answers

run manage.py collectstatic :)

like image 116
Rob Agar Avatar answered Oct 11 '22 19:10

Rob Agar