Python-beg
Python-beg

Reputation: 21

Django 1.10 - why the app does not work with DEBUG=FALSE

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

Upvotes: 0

Views: 532

Answers (1)

Eric Bulloch
Eric Bulloch

Reputation: 897

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/', ]

Upvotes: 1

Related Questions