Skip to main content

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

Version: 3.11.9 or higherRequired for Django 5.2 compatibility

Database

Production: PostgreSQL 12+Development: SQLite (included)

Memory

Minimum: 512 MB RAMRecommended: 1 GB+ for production

Storage

Minimum: 500 MBIncludes dependencies, static files, and media uploads

Dependencies

The application requires the following key packages:
requirements.txt

Environment Variables

Create a .env file in the project root with the following configuration:

Configuration Breakdown

Django’s cryptographic signing key. Generate a secure random string:
Never commit this to version control!
Database connection string parsed by dj-database-url:
Format: postgresql://username:password@host:port/databaseIf not provided, defaults to SQLite (dev only).
Enable “Sign in with Google” functionality:
  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable Google+ API
  4. Create OAuth 2.0 credentials
  5. Add authorized redirect URI: https://yourdomain.com/accounts/google/login/callback/
Powers AI-driven dashboard insights and recommendations:
  • Predictive analytics for sales trends
  • Stock replenishment suggestions
  • Customer behavior analysis
  • Automated report summaries
Get your API key from OpenAI Platform
Enable SMS notifications for:
  • Low stock alerts
  • Daily sales summaries
  • Order confirmations
Sign up at Twilio and get your credentials from the dashboard.

Local Development Setup

1

Clone Repository

2

Create Virtual Environment

3

Install Dependencies

4

Configure Environment

Copy the development .env template:
Edit .env and set minimum required variables:
  • DEBUG=True
  • SECRET_KEY=<generate-one>
5

Run Database Migrations

This creates the SQLite database and all required tables.
6

Create Superuser

Enter username, email, and password. This account has full admin access.
7

Collect Static Files

Gathers all static files (CSS, JS, images) into staticfiles/ directory.
8

Run Development Server

Access the application at http://127.0.0.1:8000Admin panel: http://127.0.0.1:8000/admin/

Production Deployment

Option 1: Railway Deployment

1

Prepare Project

Ensure these files exist in your repository:Procfile:
runtime.txt:
2

Create Railway Project

  1. Go to Railway.app
  2. Click New Project → Deploy from GitHub repo
  3. Select your repository
  4. Railway auto-detects Django and Python version
3

Add PostgreSQL Database

  1. In your Railway project, click New → Database → Add PostgreSQL
  2. Railway automatically creates DATABASE_URL environment variable
  3. The database is linked to your application
4

Configure Environment Variables

In Railway dashboard, add all production environment variables:
5

Deploy

Railway automatically deploys on every push to your main branch.Build process:
  1. Installs dependencies from requirements.txt
  2. Runs migrations automatically
  3. Collects static files
  4. Starts Gunicorn server
Monitor deployment in Railway dashboard logs.
6

Configure Custom Domain (Optional)

  1. In Railway project settings, go to Domains
  2. Add your custom domain
  3. Update DNS records as shown
  4. Update ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS with your domain

Option 2: Render Deployment

1

Prepare Build Script

Create build.sh in project root:
build.sh
Make it executable:
2

Create Render Web Service

  1. Go to Render Dashboard
  2. Click New → Web Service
  3. Connect your GitHub/GitLab repository
  4. Configure:
    • Name: inventario
    • Environment: Python 3
    • Build Command: ./build.sh
    • Start Command: gunicorn inventario.wsgi:application --workers 2 --timeout 120
3

Add PostgreSQL Database

  1. In Render dashboard, click New → PostgreSQL
  2. Create database
  3. Copy the Internal Database URL
  4. Add to your web service as DATABASE_URL environment variable
4

Configure Environment Variables

In web service Environment tab, add:
5

Deploy

Render automatically builds and deploys:
  1. Runs build.sh
  2. Executes migrations
  3. Collects static files
  4. Starts Gunicorn
Monitor in Logs tab.

Option 3: Traditional Server (Ubuntu)

1

Prepare Server

2

Setup PostgreSQL

In PostgreSQL shell:
3

Deploy Application

4

Configure Environment

Add production configuration:
5

Initialize Database

6

Configure Gunicorn

Create systemd service file:
Enable and start service:
7

Configure Nginx

Create Nginx configuration:
Enable site:
8

Setup SSL with Certbot

Static Files Configuration

Inventario uses WhiteNoise for efficient static file serving in production:
Benefits:
  • 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
Always run python manage.py collectstatic --no-input before deploying or after modifying static files.

Database Migrations

Inventario uses Django’s built-in migration system:
Production Best Practices:
  1. Always backup database before running migrations
  2. Test migrations in staging environment first
  3. Migrations run automatically during Railway/Render deployments
  4. For manual deployments, run migrations before restarting application

Health Checks & Monitoring

Application Health

Database Connection

Common Issues

Symptoms: CSS/JS files return 404 in productionSolution:
Symptoms: django.db.utils.OperationalError: FATAL: password authentication failedSolution:
  1. Verify DATABASE_URL format is correct
  2. Check database credentials
  3. Ensure database server is running and accessible
  4. For PostgreSQL, verify pg_hba.conf allows connections
Symptoms: 403 Forbidden on form submissionsSolution:
Symptoms: Google login fails with “redirect_uri_mismatch”Solution:
  1. Go to Google Cloud Console
  2. Navigate to APIs & Services → Credentials
  3. Edit your OAuth 2.0 Client
  4. Add authorized redirect URI: https://yourdomain.com/accounts/google/login/callback/
  5. Update Site domain in Django admin:
Symptoms: 502 Bad Gateway or worker restart logsSolution: Increase timeout in Procfile or systemd service:

Security Checklist

Before going to production, verify:
  • DEBUG=False in production environment
  • Strong SECRET_KEY (min 50 characters)
  • ALLOWED_HOSTS configured correctly
  • CSRF_TRUSTED_ORIGINS includes all domains
  • Database uses strong password
  • SSL/HTTPS enabled (use Certbot for free certificates)
  • SESSION_COOKIE_SECURE=True
  • CSRF_COOKIE_SECURE=True
  • .env file 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

1

Pull Latest Changes

2

Activate Virtual Environment

3

Update Dependencies

4

Run Migrations

5

Collect Static Files

6

Restart Application

Support & Resources

Django Documentation

Official Django 5.2 documentation

Railway Docs

Railway deployment guides

Render Docs

Render deployment documentation

Gunicorn Docs

Gunicorn configuration reference