You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django Admin集成CKEditor后本地正常、Apache2部署时仅显示textarea的问题求助

Fixing CKEditor Not Showing in Django Admin After Apache Deployment

Hey there, let's work through this CKEditor issue you're hitting. When your Django app runs locally with python manage.py runserver, everything works because the dev server automatically serves static files—but Apache needs explicit configuration to handle them, which is almost always the root cause here. Let's break down the steps to fix this:

1. Make sure you've collected all static files

Django doesn't automatically serve static files in production mode, so you need to gather all static assets (including CKEditor's files) into a single directory using the collectstatic command:

python manage.py collectstatic
  • First, double-check your settings.py has the correct static file settings:
    STATIC_URL = '/static/'
    # Use an absolute path here, e.g., for a project at /var/www/my_django_app/
    STATIC_ROOT = '/var/www/my_django_app/static/'
    
  • After running collectstatic, verify that the ckeditor folder exists inside your STATIC_ROOT directory—this should contain all the JS, CSS, and other assets CKEditor needs.

2. Configure Apache to serve static files

You need to tell Apache where your static files live so it can serve them to visitors. Edit your Apache virtual host configuration file (usually located at /etc/apache2/sites-available/your_site.conf) and add these lines:

# Serve static files
Alias /static/ /var/www/my_django_app/static/
<Directory /var/www/my_django_app/static/>
    Require all granted
    Options -Indexes
</Directory>
  • Replace /var/www/my_django_app/static/ with your actual STATIC_ROOT path.
  • Ensure Apache has permission to read this directory:
    sudo chown -R www-data:www-data /var/www/my_django_app/static/
    sudo chmod -R 755 /var/www/my_django_app/static/
    

3. Verify CKEditor's base path configuration

Sometimes CKEditor can't find its assets if the base path isn't set correctly in production. Add this to your settings.py:

CKEDITOR_BASEPATH = STATIC_URL + 'ckeditor/ckeditor/'

This ensures CKEditor looks for its files in the correct static directory served by Apache.

4. Check for 404 errors in the browser

Open your browser's developer tools (F12 → Console tab) and reload the Admin page. If you see 404 errors for CKEditor's JS/CSS files, that confirms the static files aren't being served properly. Go back to steps 1 and 2 to fix the path or Apache configuration.

5. Restart Apache after changes

Don't forget to apply your Apache configuration changes by restarting the service:

sudo systemctl restart apache2

6. Ensure DEBUG is set to False

In production, your settings.py should have DEBUG = False—when DEBUG is True, Django might handle static files differently, but it's not safe for production. If you left DEBUG on, switch it off and re-run collectstatic just to be sure.

Most of the time, running collectstatic correctly and configuring Apache's static file alias fixes this issue. Start with those two steps, and you should see CKEditor load up in the Admin panel shortly.

内容的提问来源于stack exchange,提问作者sandeep kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 06:52:28