Django - Website Bootstrap Design Breaks For Production

252 views
Skip to first unread message

Chris Nowak

unread,
Jul 16, 2015, 5:24:42 PM7/16/15
to django...@googlegroups.com

I'm following the Try Django Tutorial #37 on Youtube and around the 11 minute mark, after the author sets DEBUG = False and ALLOWED_HOSTS = ['*'] to put the website into production mode, he runs the server again and the website appears nicely designed on his end. However, when I run it again on my end while following along, the Bootstrap design of the website completely falls apart with some images not even showing up.

I'm suspecting that this has something to with the static_in_env vs. static_in_pro when it comes development vs. production, but I'm not sure, just a beginner. Also, the following is what I'm getting in my command terminal:


[16/Jul/2015 17:31:20]"GET /static/css/bootstrap.min.css HTTP/1.1" 404 102
[16/Jul/2015 17:31:20]"GET /static/css/custom.css HTTP/1.1" 404 95
[16/Jul/2015 17:31:20]"GET /static/img/marketing1.jpg HTTP/1.1" 404 99
[16/Jul/2015 17:31:20]"GET /static/css/navbar-static-top.css HTTP/1.1" 404 106
[16/Jul/2015 17:31:20]"GET /static/img/mvp_landing_logo.png HTTP/1.1" 404 105
[16/Jul/2015 17:31:20]"GET /static/js/bootstrap.min.js HTTP/1.1" 404 100
[16/Jul/2015 17:31:20]"GET /static/js/ie10-viewport-bug-workaround.js HTTP/1.1" 404 115


I have attached screen shots of the website and how it's breaking. Any help or advice on how to fix this issue is appreciated. Thanks.

Screen Shot 2015-07-16 at 11.52.00 AM.png
Screen Shot 2015-07-16 at 11.52.02 AM.png

Andreas Kuhne

unread,
Jul 17, 2015, 5:45:30 AM7/17/15
to django...@googlegroups.com
Hi,

There is a difference to running the runserver in development and production mode. In development mode the server automatically serves all of you static files (JS and CSS). In production mode you should have a webserver in front of the uwsgi server that serves the python code. For example you can use Apache and nginx (see http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html and https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/). 

If you check in the output of the server you can see that the static files are not found([16/Jul/2015 17:31:20]"GET /static/css/bootstrap.min.css HTTP/1.1" 404 102). The 404 means that the file cannot be found, and you can't get a page with the correct stylesheet when the stylesheet is not found.

You CAN try to run the following : 
python manage.py collectstatic

In the project directory and create the static files, that then will be served from your runserver process.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f5998fb8-3910-430b-a25b-8b48464f9c24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Timothy W. Cook

unread,
Jul 17, 2015, 7:25:23 AM7/17/15
to django...@googlegroups.com
You may find that even after running collectstatic the dev server doesn't see the static files. 
You can add the --insecure  option to runserver, with DEBUG=False and it should work as expected. 


For more options, visit https://groups.google.com/d/optout.



--

============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Reply all
Reply to author
Forward
0 new messages