When I use rest-framework in my localhost it works well :
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
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.
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.
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.
run manage.py collectstatic
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With