A modern Django application that integrates the Beefree SDK email editor using a contemporary frontend build process with Vite and npm.
- Modern Frontend Build: Uses Vite for fast builds and hot reloading
- npm Package Management: Proper dependency management with
@beefree.io/sdk
- Responsive Design: Full-screen editor with modern CSS
- Secure Token Handling: Server-side token generation for BeeFree SDK
- Development Workflow: Hot reloading for both frontend and backend
- Python 3.8+
- Node.js 18+
- npm 9+
- BeeFree Account: Get your
BEE_CLIENT_ID
andBEE_CLIENT_SECRET
from BeeFree
git clone https://github.com/BeefreeSDK/beefree-django-app-demo.git
cd Django-beefree-demo
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate
# Install Python dependencies
pip install -r requirements.txt
# Install npm dependencies
npm install
# Install Beefree SDK package
npm install @beefree.io/sdk
# Build frontend assets
npm run build
Create a .env
file in the project root:
# Django settings
DJANGO_SECRET_KEY=your-secret-key-here
DJANGO_DEBUG=1
DJANGO_ALLOWED_HOSTS=*
# BeeFree credentials
BEE_CLIENT_ID=your-bee-client-id
BEE_CLIENT_SECRET=your-bee-client-secret
python manage.py migrate
python manage.py runserver
Visit http://localhost:8000/
to see the application!
For convenience, use the provided build script:
./build.sh
This script will:
- Check Node.js version
- Install npm dependencies
- Install Beefree SDK package
- Build frontend assets
- Provide next steps
# Terminal 1: Start Django server
python manage.py runserver
# Terminal 2: Start Vite dev server
npm run dev
The Vite dev server will run on http://localhost:3000
with hot reloading and proxy API requests to Django on http://localhost:8000
.
npm run dev # Start Vite dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues
Django-beefree-demo/
βββ beefree_demo/ # Django project settings
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ editor/ # Django app
β βββ views.py # API endpoints and views
β βββ urls.py # URL routing
β βββ apps.py
βββ frontend/ # Frontend source code
β βββ src/
β β βββ editor.js # Main editor logic
β β βββ styles.css # Modern CSS styles
β βββ index.html # Development template
βββ templates/ # Django templates
β βββ editor/
β βββ index.html # Production template
βββ static/ # Built assets (generated)
β βββ js/
β βββ css/
βββ package.json # npm dependencies
βββ vite.config.js # Vite build configuration
βββ requirements.txt # Python dependencies
βββ manage.py # Django management
βββ README.md
- Django Backend: Handles authentication and serves the main page
- BeeFree API: Securely generates tokens server-side
- Frontend Build: Vite bundles the BeeFree SDK and custom code
- Browser: Loads the editor and handles user interactions
index
: Renders the main editor pagebee_auth
: POST endpoint that generates BeeFree tokens
- Imports
@beefree.io/sdk
from npm - Fetches authentication token from Django
- Initializes the Beefree editor with full-screen layout
- Handles save events and error states
- Vite: Bundles JavaScript and CSS with optimizations
- Static Files: Outputs to Django's static directory
- Development: Hot reloading and API proxying
Edit the initialTemplate
object in frontend/src/editor.js
to change the default email template.
Modify frontend/src/styles.css
to customize the layout and appearance.
Adjust the beeConfig
object in frontend/src/editor.js
to customize the editor behavior.
- Environment Variables: Never commit
.env
files - Token Generation: Always generate Beefree SDK tokens server-side
- CORS: Configured for local development only
- Dependencies: Regularly update npm and pip packages
Editor not loading:
- Check browser console for errors
- Verify Beefree SDK credentials in
.env
- Ensure
npm run build
completed successfully - Verify
@beefree.io/sdk
package is installed
Static files not found:
- Run
npm run build
to generate assets - Check that Django's
STATIC_URL
is configured correctly
Build errors:
- Ensure Node.js 18+ is installed
- Delete
node_modules
and runnpm install
- Ensure
@beefree.io/sdk
package is installed - Check for dependency conflicts
Token errors:
- Verify
BEE_CLIENT_ID
andBEE_CLIENT_SECRET
in.env
- Restart Django server after changing environment variables
- Use browser dev tools to inspect network requests
- Check Django logs for server-side errors
- Use
npm run dev
for frontend development with hot reloading
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.