0

I am completely beginner of Django / Python.

I wrote my app in Django 1.10, everything works good and now I would like to move the app at production server.

So, I have set the DEBUG on FALSE and suddenly whole app stopped working. It means, generally an app works, but static links doesn't work, the program does not see js, css files.

Do you know - why?

Thanks

  • Welcome to Stack Overflow! This question will probably be closed as a duplicate or "too-broad" soon. However, don't be discouraged! If the answers (either here or in duplicate questions) don't fully address your question please edit it to include why and flag this for re-opening. Thanks! – tutuDajuju May 12 '17 at 08:02
  • Possible duplicate of [Why does DEBUG=False setting make my django Static Files Access fail?](http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – tutuDajuju May 12 '17 at 08:03

1 Answers1

1

The development server knows how to serve static files but you have to set some settings for this to work in production. You can read about it here.

That will also point you to this page.

You need to do the following:

  1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
  2. In your settings file, define STATIC_URL.
  3. Use the static template tag to build the URL for the given relative path. For example:

{% load static %} <img src="{% static "my_app/example.jpg" %}" alt="My image"/>

  1. Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg.
  2. Set the STATICFILES_DIRS setting in your settings file. For example:

STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), '/var/www/static/', ]

Eric Bulloch
  • 827
  • 6
  • 10