Answer the question
In order to leave comments, you need to log in
What to do if css styles disappear when Debug: False in Django?
In general, when launching a site with everything turned Debug=True
on settings.py
normally, the site is displayed correctly . But when I install Debug=False
and launch the site, it crashes completely, leaving only a hodgepodge of text, in general, a dry HTML template. Also, when I run the site on port 80, the problem seems to disappear. But when I launch the site and throw a tunnel through ngrok, it returns again. So. How to fix the problem described above. In short: I set Debug = True, the site works fine, when I set Debug=False - CSS styles fly off.
Answer the question
In order to leave comments, you need to log in
I found the answer, as I understand it, when Debug=True
Django stops structuring data in static, which is why css and everything else from static disappears. I used this command manage.py runserver --insecure
and it seems to work, but I think there are some pitfalls here. I took it all from here: *clickable* .
Serve static with Nginx. It will be quick and easy.
You need to collect all the statics in one folder using manage.py collectstatic
nginx config to work in tandem with the django UWSGI server
server {
listen 80;
server_name site.domain.ru;
charset utf-8;
error_log /usr/local/www/project/nginx_error.log;
client_max_body_size 15m;
location /robots.txt {
alias /usr/local/www/project/robots.txt;
}
location /media {
alias /usr/local/www/project/src/media; # your Django project's media files - amend as required
}
location /static {
alias /usr/local/www/project/static; # your Django project's static files - amend as required
}
location /mediashare {
alias /usr/local/www/project/mediashare; #
}
location / {
uwsgi_read_timeout 600;
uwsgi_send_timeout 600;
uwsgi_pass 127.0.0.1:5004;
include uwsgi_params;
add_header X-uri "$arg_page";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question