CKEditor breaks when debug = False

I'm nearing the end of my project, a blog. I have set DEBUG = False for security.

This breaks my CKEDITOR, making it just not appear at all when the page is loaded.

When DEBUG = True it works fine.

template:

<form class="text-center m-3" action="." method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.media }}
{{ form.as_p }}
<button class="btn btn-signup right" id="button">Post &raquo;</button>

forms.py:

class PostForm (forms.ModelForm):
class Meta:
    model = Post
    fields = ('title', 'excerpt', 'featured_image',
              'content', 'author')

    widgets = {
        'title': forms.TextInput(attrs={'placeholder':
                                        'Give it a catchy title'}),
        'excerpt': forms.TextInput(attrs={'placeholder':
                                          'E.g. My first ever post'}),
        'content': forms.Textarea(
            attrs={'placeholder':
                   '<p>Wrap your content in these P tags to create a paragraph</p> \
                    \n\n<b>Wrap your words in these B tags \
                    to make them bold</b>'}),
        'author': forms.TextInput(
            attrs={'class': 'form-control', 'value': '',
                   'id': 'user', 'type': 'hidden'}),
    }

This is a consequence of the fact that Django does not serve static files or media files in production. Indeed, As is specified in the Static file development view section of the documentation:

This view will only work if DEBUG is True.

That’s because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.

Normally you should configure the nginx, apache, or other web server to serve static and media files. These web servers are likely more efficient and have more dedicated tooling for security. This is the main reason why Django is not supposed to serve static and media files in production.

Back to Top