28👍
✅
Third party app
All You need is dj-static package.
pip install dj-static
Configure your static assets in settings.py:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
Then, update your wsgi.py file to use dj-static:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
Pure Django
Add to Your urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
...
urlpatterns += staticfiles_urlpatterns()
4👍
you can server the static file from nginx server. In the server setting.
https://stackoverflow.com/questions/tagged/django-settings
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://0.0.0.0:8000;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Ssl on;
proxy_redirect off;
}
location /static/ {
autoindex on;
alias /home/ec2-user/app/static/;
}
}
- Django `bulk_create` with related objects
- Object is not subscriptable using django and python
- ImportError: cannot import name generic
- Creating a profile model with both an InlineAdmin and a post_save signal in Django
Source:stackexchange.com