Embed Django Apps

Introduction #

SmartChart can be embedded as a Django App plugin into your existing Django project, sharing the same user system and database without independent deployment. Suitable for teams with existing Django systems to quickly integrate visualization capabilities.

Related Video

Use Cases #

  • Use SmartChart directly as an application plugin in your Django project
  • Integrate with existing Django user system

Usage #

Follow these steps to integrate SmartChart into your Django project:

Step 1: Add to INSTALLED_APPS

INSTALLED_APPS = [
    ....
    ....
    'smart_chart.echart',
    'smart_chart.oa',
    'smart_chart.scheduler'
]

Step 2: Comment out XFrameOptionsMiddleware

In MIDDLEWARE, comment out django.middleware.clickjacking.XFrameOptionsMiddleware

Step 3: Ensure Templates config is correct

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],   # Required
        'APP_DIRS': True,                   # Also required
        .....
    },
]

Step 4: Set timezone (support Chinese)

LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False  # Must be False

Step 5: Add imports

from django.conf.urls import include
from django.views.generic import RedirectView

Step 6: Add routes

path('echart/', include('smart_chart.echart.urls')),
path('', RedirectView.as_view(url='/echart/index/')),  # Homepage, customizable

Step 7: Initialize database

python manage.py makemigrations
python manage.py migrate

Step 8: Create admin account (skip if exists)

python manage.py createsuperuser

Step 9: Start service

python manage.py runserver

Step 10: Component upgrade initialization ⚠️ Important!

Click "Product Authentication" on homepage -> "Activate Advanced Features" -> "Component Upgrade" to initialize

Component Upgrade

Note #

Generally, issues encountered with Django are not caused by SmartChart. The author cannot provide support, suggest using paid Q&A.