0

This link: https://docs.djangoproject.com/en/1.8/howto/static-files/ starts off by explaining a "grossly inefficient and probably insecure, unsuitable for production" way of serving files. It also explains how to use

 django.contrib.staticfiles.views.serve()

which is "not suitable for production use!". I don't want to have to code an entire Django project, finish it and then end up having to change a lot of code right before deploying because the current code is "grossly inefficient and probably insecure, unsuitable for production".

With that said, what's the best approach (the approach which doesn't require a lot of extra work just to move my app from development to production) to take when serving static files? I'm asking because I've never been through the process of deploying a Django app before and when deploying, I don't want to end up saying to myself "wow, I should have done it that way rather than this way".

SilentDev
  • 20,997
  • 28
  • 111
  • 214
  • You should set STATIC_ROOT in your settings.py file and then run 'python manage.py collectstatic' to have all of your static files into your root directory. If you use nginx for example, you just have to route '/static' through your static folder. – Charlesthk May 08 '15 at 22:46
  • 1
    https://docs.djangoproject.com/en/1.8/howto/static-files/deployment/ you need to use a file server for this. Nginx is most common. In it, you configure the file server to serve files at a particular directory, to a particular URL. It is unrelated to django and will not cause a step backwards by using the static file serving in development. – Yuji 'Tomita' Tomita May 08 '15 at 23:42
  • What the documents are saying is just - hey, you don't need to configure this when in Development - Django.contrib.staticfiles.views.serve() is a convenient way to do this. As said by Charlesthk and Yuji you will need to configure your server (Apache, Nginx, etc) to serve your static files. – André Duarte May 09 '15 at 01:46

1 Answers1

1

You don't change any code, because it's not your code that serves static files. You need to configure your web server to do it; which is fine, because you're configuring your web server anyway for deployment.

The whole point of the staticfiles app in Django is just that, that it manages files for you in development and puts them in a single place for deployment so you can point your web server at them.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895