Reputation: 2442
I'm trying to run my django site in deployment mode with DEBUG=False
. In fact when i do a python manage.py collectstatic
it will collect all static files into my folder /mysite/static
. But when i load my homepage my static files wont load Not Found
occurs.
My Django version is 1.10.4 Here is my STATIC ROOT definition and urls folder:
In settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static") (i tried also just only 'static')
MEDIA_ROOT = BASE_DIR + '/mysite/media'
MEDIA_URL = '/media/'
my urls.py:
urlpatterns = [
url(r'', include('mysite.urls')),
]
urlpatterns += staticfiles_urlpatterns()
I notice that is not assuming my collectstatic folder instead is considering the static file in app folder.
doing python manage.py findstatic mysite/js/javascript.js
Found 'app/js/javascript.js' here:
/home/user/mysite/app/static/app/js/javascript.js
Well, once that DEBUG=False
it should give something like:
/home/user/mysite/static/app/js/javascript.js
Upvotes: 0
Views: 1994
Reputation: 301
Depending on your production setup, you may have to set up your Apache or nginx config file to point to static content. For example, in nginx, you can add a "location /static/ {...}" entry, eg. something like this:
server {
server_name mysite.com;
listen 443;
listen [::]:443;
ssl on;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/private.key;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
allow all;
alias /your/base/dir/here/.../mysite/static/;
}
location / {
...
}
}
Upvotes: 0
Reputation: 1155
At production server, your nginx or apache should serve the static files. When Debug = False, django stops serving the static files. Please share your nginx settings, I can help you out there...
For more info, check this link
Upvotes: 2