Overview
Inventario is a Django 5.2 application designed for easy deployment on cloud platforms or traditional servers. This guide covers local development setup, environment configuration, and production deployment.System Requirements
Python
Database
Memory
Storage
Dependencies
The application requires the following key packages:Environment Variables
Create a.env file in the project root with the following configuration:
Configuration Breakdown
SECRET_KEY - Required
SECRET_KEY - Required
DATABASE_URL - Production Required
DATABASE_URL - Production Required
dj-database-url:postgresql://username:password@host:port/databaseIf not provided, defaults to SQLite (dev only).Google OAuth - Optional
Google OAuth - Optional
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
https://yourdomain.com/accounts/google/login/callback/
OpenAI API Key - Optional
OpenAI API Key - Optional
- Predictive analytics for sales trends
- Stock replenishment suggestions
- Customer behavior analysis
- Automated report summaries
Twilio Configuration - Optional
Twilio Configuration - Optional
- Low stock alerts
- Daily sales summaries
- Order confirmations
Local Development Setup
Clone Repository
Create Virtual Environment
Install Dependencies
Configure Environment
.env template:.env and set minimum required variables:DEBUG=TrueSECRET_KEY=<generate-one>
Run Database Migrations
Create Superuser
Collect Static Files
staticfiles/ directory.Run Development Server
http://127.0.0.1:8000Admin panel: http://127.0.0.1:8000/admin/Production Deployment
Option 1: Railway Deployment
Prepare Project
Create Railway Project
- Go to Railway.app
- Click New Project → Deploy from GitHub repo
- Select your repository
- Railway auto-detects Django and Python version
Add PostgreSQL Database
- In your Railway project, click New → Database → Add PostgreSQL
- Railway automatically creates
DATABASE_URLenvironment variable - The database is linked to your application
Configure Environment Variables
Deploy
- Installs dependencies from
requirements.txt - Runs migrations automatically
- Collects static files
- Starts Gunicorn server
Configure Custom Domain (Optional)
- In Railway project settings, go to Domains
- Add your custom domain
- Update DNS records as shown
- Update
ALLOWED_HOSTSandCSRF_TRUSTED_ORIGINSwith your domain
Option 2: Render Deployment
Prepare Build Script
build.sh in project root:Create Render Web Service
- Go to Render Dashboard
- Click New → Web Service
- Connect your GitHub/GitLab repository
- Configure:
- Name: inventario
- Environment: Python 3
- Build Command:
./build.sh - Start Command:
gunicorn inventario.wsgi:application --workers 2 --timeout 120
Add PostgreSQL Database
- In Render dashboard, click New → PostgreSQL
- Create database
- Copy the Internal Database URL
- Add to your web service as
DATABASE_URLenvironment variable
Configure Environment Variables
Deploy
- Runs
build.sh - Executes migrations
- Collects static files
- Starts Gunicorn
Option 3: Traditional Server (Ubuntu)
Prepare Server
Setup PostgreSQL
Deploy Application
Configure Environment
Initialize Database
Configure Gunicorn
Configure Nginx
Setup SSL with Certbot
Static Files Configuration
Inventario uses WhiteNoise for efficient static file serving in production:- Serves compressed static files (gzip/brotli)
- Adds far-future cache headers
- No CDN required for small to medium applications
- Works seamlessly with Django’s collectstatic
Database Migrations
Inventario uses Django’s built-in migration system:- Always backup database before running migrations
- Test migrations in staging environment first
- Migrations run automatically during Railway/Render deployments
- For manual deployments, run migrations before restarting application
Health Checks & Monitoring
Application Health
Database Connection
Common Issues
Static files not loading (404 errors)
Static files not loading (404 errors)
Database connection errors
Database connection errors
django.db.utils.OperationalError: FATAL: password authentication failedSolution:- Verify
DATABASE_URLformat is correct - Check database credentials
- Ensure database server is running and accessible
- For PostgreSQL, verify
pg_hba.confallows connections
CSRF verification failed
CSRF verification failed
Google OAuth redirect mismatch
Google OAuth redirect mismatch
- Go to Google Cloud Console
- Navigate to APIs & Services → Credentials
- Edit your OAuth 2.0 Client
- Add authorized redirect URI:
https://yourdomain.com/accounts/google/login/callback/ - Update Site domain in Django admin:
Gunicorn worker timeout
Gunicorn worker timeout
Security Checklist
Before going to production, verify:-
DEBUG=Falsein production environment - Strong
SECRET_KEY(min 50 characters) -
ALLOWED_HOSTSconfigured correctly -
CSRF_TRUSTED_ORIGINSincludes all domains - Database uses strong password
- SSL/HTTPS enabled (use Certbot for free certificates)
-
SESSION_COOKIE_SECURE=True -
CSRF_COOKIE_SECURE=True -
.envfile not committed to version control - Regular database backups configured
- Admin account uses strong password
Performance Optimization
Database Connection Pooling
Gunicorn Workers
Calculate optimal worker count:Static File Compression
WhiteNoise automatically compresses static files. Verify:Backup & Recovery
Database Backup
Automated Backups (Ubuntu)
Updating the Application
Pull Latest Changes
Activate Virtual Environment
Update Dependencies
Run Migrations
Collect Static Files
Restart Application