When you put Django Nova behind a public demo, the most immediate change is that every request is now visible to the world: performance, error rates, and user behavior become measurable at scale, and the security surface expands from your local machine to the open internet. This article explains what actually shifts—from deployment settings and database behavior to session handling and resource limits—so you know what to expect and how to adapt.
Background: What Django Nova Is
Django Nova is a project template or starter kit built on the Django web framework, typically bundling common packages like Django REST Framework, Celery, Redis, and Docker. It is designed to give developers a head start on production-ready features such as user authentication, background tasks, and API endpoints. In a local development environment, you run it with Django’s built-in development server, which is single-threaded and not optimized for concurrent traffic. The database is usually SQLite, and static files are served directly by Django. When you move to a public demo, you are effectively shifting from a single-user, trusted environment to a multi-user, untrusted one. That shift forces changes in how the application is configured, deployed, and monitored.
What Actually Changes When You Go Public
The most obvious change is that the development server is no longer sufficient. Django’s runserver is explicitly documented as not for production use. It can handle a handful of users but will choke under real load, and it is not secure against malformed HTTP requests. For a public demo, you need a proper WSGI server like Gunicorn or uWSGI, fronted by a reverse proxy such as Nginx. This changes how you set environment variables, how you manage static and media files, and how you handle HTTPS.
Another major shift is the database. SQLite works fine for local development, but it locks the entire database on writes, which becomes a bottleneck with concurrent users. A public demo typically moves to PostgreSQL or MySQL. This migration requires changes in your settings.py and often in your data models—for example, using PostgreSQL-specific fields like ArrayField or JSONField that have no SQLite equivalent.
Session handling changes too. In development, sessions are often stored in the database or in signed cookies. In a public demo, you might switch to Redis or Memcached for session storage to improve performance and allow multiple server instances. This also affects how you handle user authentication, CSRF tokens, and security headers.
How to Prepare Your Django Nova App for a Public Demo
Before you expose your app, go through this checklist:
- Set
DEBUG = False. Leaving debug mode on leaks stack traces, settings, and local file paths to any visitor. This is the most common mistake. - Configure
ALLOWED_HOSTS. In development, it’s often empty or set to['*']. For a public demo, list your actual domain and subdomains to prevent HTTP Host header attacks. - Use environment variables for secrets. Move your
SECRET_KEY, database credentials, and API keys out ofsettings.pyinto environment variables or a secrets manager. Never commit them to version control. - Serve static and media files properly. Use WhiteNoise or a CDN for static files, and configure a separate storage for user uploads (e.g., S3 or local disk with Nginx serving them).
- Enable HTTPS. Use Let’s Encrypt with Certbot or a reverse proxy that terminates TLS. This is non-negotiable for security and for browser features like geolocation or service workers.
- Set security headers. Django’s
SecurityMiddlewarecan addX-Content-Type-Options,X-Frame-Options, andStrict-Transport-Securityheaders. Enable them. - Add rate limiting. A public demo will attract bots and scrapers. Use
django-ratelimitor a reverse proxy rule to throttle requests.
Performance and Resource Limits
Your local machine has unlimited memory and CPU compared to a small VPS. A public demo on a $5/month server will have 1GB RAM and limited CPU. Django Nova’s Celery workers, Redis, and database will compete for that memory. You need to set limits:
- Gunicorn workers: A common formula is
2 * CPU cores + 1. For a single-core VPS, that’s 3 workers. Each worker consumes memory, so monitor usage. - Database connections: PostgreSQL defaults to 100 connections. Set
CONN_MAX_AGEto keep connections alive, but be aware of connection limits. - Celery concurrency: Set
--concurrency=2or lower. Background tasks can pile up if you have many users uploading files or sending emails. - Timeout settings: Set Gunicorn’s
--timeoutto 30 seconds or less. If a request takes longer, the worker is killed and restarted.
You should also implement caching. Django’s cache framework can use Redis or Memcached. Cache querysets that are expensive to compute, like user profiles or dashboard stats. This reduces database load significantly.
Security Considerations Specific to a Public Demo
Security is the biggest change. In development, you trust everyone on your local network. On the public internet, you must assume every request is malicious. Key areas:
- User input validation. Django’s forms and DRF serializers help, but you must be strict with file uploads—limit file size, check content types, and store uploads outside the web root.
- Authentication. If you allow user registration, enforce strong passwords and consider adding email verification. Use Django’s built-in login and password reset views; they are battle-tested.
- CSRF and CORS. By default, Django protects against CSRF. If you have a separate frontend (e.g., React), configure CORS properly with
django-cors-headersand only allow your own domain. - SQL injection and XSS. Django’s ORM and template engine protect against these if you use them correctly. Avoid raw SQL and mark user-generated content as
|safeonly when necessary. - Rate limiting and brute-force protection. Use
django-axesordjango-ratelimiton login and password reset endpoints.
Monitoring and Logging
When the demo is public, you need to know what’s happening. Set up logging to a file or a service like Sentry. Django’s logging configuration can capture errors, warnings, and info messages. You should also monitor:
- Error rates: Use Sentry or a simple log aggregator. Look for 500 errors and unhandled exceptions.
- Response times: Use Django’s
django-statsdor middleware to measure request duration. If the 95th percentile is over 500ms, investigate. - Resource usage: Use
psutilin a management command or a tool like Netdata. Watch memory and CPU.
Set up alerts for disk space, memory, and service downtime. A public demo that goes down reflects poorly on your project, even if it’s just a demo.
Common Problems and How to Fix Them
Here are issues you will likely encounter:
- “DisallowedHost” error: This means
ALLOWED_HOSTSis misconfigured. Add your domain. - Static files 404: In production, Django does not serve static files. Use WhiteNoise or collectstatic to a directory served by Nginx.
- Database connection refused: Check your database host and credentials. If using Docker, ensure the database container is on the same network.
- Celery tasks not executing: Ensure the Celery worker is running and that the broker (Redis) is accessible. Check the queue.
- Slow page loads: Enable Django’s
django-debug-toolbaronly in development. In production, use caching and database indexing.
Frequently Asked Questions
Do I need to change my Django Nova code for a public demo?
Usually not the core code, but you will need to adjust settings and add deployment files. For example, you might need to add a requirements.txt for production, configure settings.py with environment variables, and write a Dockerfile if you use Docker. The application code itself—views, models, templates—can remain the same.
Can I keep SQLite for a public demo?
You can for a very low-traffic demo, but it is not recommended. SQLite locks the entire database on writes, so if two users try to update data at the same time, one will get an error. Also, SQLite does not support some features like ArrayField or concurrent connections. For a public demo, use PostgreSQL or MySQL.
How do I handle file uploads in a public demo?
You need to configure a media storage backend. In development, Django serves media files from a local directory. In production, you should store them on a dedicated volume or cloud storage like S3. Use django-storages to switch backends easily. Also, limit file size and validate file types to prevent abuse.
What is the safest way to expose a Django demo?
Use a reverse proxy like Nginx with HTTPS, set DEBUG=False, and restrict access if possible—for example, with HTTP basic auth or by IP allowlist. Also, use a separate database user with limited permissions, and never expose your admin panel without strong credentials and two-factor authentication.
Will my demo be faster if I use a CDN?
Yes, for static files. A CDN caches your CSS, JavaScript, and images on edge servers, reducing load on your application server. For dynamic content, you need caching at the database or application level. Use Django’s cache framework with Redis or Memcached.
How do I debug errors after going public?
Set up logging to a file or use a service like Sentry. In Django, configure LOGGING in settings.py to capture exceptions and warnings. You can also use django-extensions to run runserver with --debug temporarily, but never leave it on.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Arctic Sea Ice Forecasts Disagree: What to Do
- MySQL Workbench to VPS: SSH Tunnel Setup
- Bluesky Beginners Guide: How to Get Started5.00 min/km
- LG V20 Won’t Turn On? Fixed
- Snagit vs Camtasia: Which One Do You Need?
- Scale a Small Business Without Losing Culture