Overview
Aqua-IoT uses Django’s settings system for configuration. All settings are defined in Django/painel/settings.py. This guide covers the essential configuration options for development and production environments.
Database Configuration
PostgreSQL (Recommended)
The application is configured to use PostgreSQL by default. Update the database settings in settings.py:
Django/painel/settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.postgresql_psycopg2' ,
'NAME' : 'aqua' ,
'USER' : 'postgres' ,
'PASSWORD' : 'your_secure_password' ,
'HOST' : 'localhost' ,
'PORT' : '5432' ,
}
}
Security Alert : Never commit database passwords to version control. Use environment variables or a secure configuration management system in production.
Environment Variables
For production, use environment variables for sensitive configuration:
Django/painel/settings.py
import os
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.postgresql_psycopg2' ,
'NAME' : os.environ.get( 'DB_NAME' , 'aqua' ),
'USER' : os.environ.get( 'DB_USER' , 'postgres' ),
'PASSWORD' : os.environ.get( 'DB_PASSWORD' ),
'HOST' : os.environ.get( 'DB_HOST' , 'localhost' ),
'PORT' : os.environ.get( 'DB_PORT' , '5432' ),
}
}
SQLite (Development Only)
For quick development setups, you can use SQLite instead:
Django/painel/settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.sqlite3' ,
'NAME' : BASE_DIR / 'db.sqlite3' ,
}
}
SQLite is not recommended for production use, especially with concurrent write operations from IoT devices.
Security Settings
Secret Key
The SECRET_KEY is used for cryptographic signing. Never use the default key in production :
Django/painel/settings.py
# INSECURE - Development only
SECRET_KEY = 'django-insecure-&fuwcyavgdzl5vexco-_7ef-y-!(wcvtf59_awaoeype42r0p$'
# SECURE - Production
SECRET_KEY = os.environ.get( 'DJANGO_SECRET_KEY' )
Generate a new secret key:
from django.core.management.utils import get_random_secret_key
print (get_random_secret_key())
Debug Mode
Critical : Always set DEBUG = False in production. Debug mode exposes sensitive information.
Django/painel/settings.py
# Development
DEBUG = True
# Production
DEBUG = False
Allowed Hosts
Configure allowed hostnames for production:
Django/painel/settings.py
# Development
ALLOWED_HOSTS = []
# Production
ALLOWED_HOSTS = [
'yourdomain.com' ,
'www.yourdomain.com' ,
'your-server-ip' ,
]
Static Files Configuration
Static files (CSS, JavaScript, images) are configured with the following settings:
Django/painel/settings.py
# URL prefix for static files
STATIC_URL = '/static/'
# Directory where collectstatic will gather files
STATIC_ROOT = os.path.join( BASE_DIR , 'static_files' )
# Additional locations for static files
STATICFILES_DIRS = [
os.path.join( BASE_DIR , "static" ),
'/var/www/static/' , # For production
]
For user-uploaded content:
Django/painel/settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join( BASE_DIR , 'static_media' )
Collecting Static Files
Run this command before deployment:
python manage.py collectstatic
REST Framework Configuration
The application uses Django REST Framework with token authentication:
Django/painel/settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES' : [
'rest_framework.authentication.TokenAuthentication' ,
'rest_framework.authentication.SessionAuthentication' ,
],
}
Installed Apps
Django/painel/settings.py
INSTALLED_APPS = [
'django.contrib.admin' ,
'django.contrib.auth' ,
'django.contrib.contenttypes' ,
'django.contrib.sessions' ,
'django.contrib.messages' ,
'django.contrib.staticfiles' ,
'rest_framework' ,
'rest_framework.authtoken' ,
'sensores' , # Main application
]
Internationalization Settings
The application is configured for Brazilian Portuguese timezone:
Django/painel/settings.py
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True
USE_L10N = True
USE_TZ = True
To change the timezone, use any valid timezone name :
TIME_ZONE = 'UTC' # Universal time
TIME_ZONE = 'America/New_York' # Eastern US
TIME_ZONE = 'Europe/London' # UK
MQTT Broker Configuration
For IoT device communication, configure your MQTT broker connection. Add these settings to your configuration:
# MQTT Broker Configuration
MQTT_BROKER_HOST = os.environ.get( 'MQTT_BROKER_HOST' , 'localhost' )
MQTT_BROKER_PORT = int (os.environ.get( 'MQTT_BROKER_PORT' , 1883 ))
MQTT_USERNAME = os.environ.get( 'MQTT_USERNAME' , '' )
MQTT_PASSWORD = os.environ.get( 'MQTT_PASSWORD' , '' )
MQTT_KEEPALIVE = 60
Middleware Configuration
The default middleware stack includes:
Django/painel/settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware' ,
'django.contrib.sessions.middleware.SessionMiddleware' ,
'django.middleware.common.CommonMiddleware' ,
'django.middleware.csrf.CsrfViewMiddleware' ,
'django.contrib.auth.middleware.AuthenticationMiddleware' ,
'django.contrib.messages.middleware.MessageMiddleware' ,
'django.middleware.clickjacking.XFrameOptionsMiddleware' ,
]
Template Configuration
Templates are configured to load from the templates directory:
Django/painel/settings.py
TEMPLATES = [
{
'BACKEND' : 'django.template.backends.django.DjangoTemplates' ,
'DIRS' : [os.path.join( BASE_DIR , 'templates' )],
'APP_DIRS' : True ,
'OPTIONS' : {
'context_processors' : [
'django.template.context_processors.debug' ,
'django.template.context_processors.request' ,
'django.contrib.auth.context_processors.auth' ,
'django.contrib.messages.context_processors.messages' ,
],
},
},
]
Password Validation
Django enforces strong password policies by default:
Django/painel/settings.py
AUTH_PASSWORD_VALIDATORS = [
{
'NAME' : 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.MinimumLengthValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.CommonPasswordValidator' ,
},
{
'NAME' : 'django.contrib.auth.password_validation.NumericPasswordValidator' ,
},
]
Environment-Specific Configuration
Development Settings
Create a .env file for local development:
DJANGO_DEBUG = True
DJANGO_SECRET_KEY = your-dev-secret-key
DB_NAME = aqua
DB_USER = postgres
DB_PASSWORD = local_password
DB_HOST = localhost
DB_PORT = 5432
MQTT_BROKER_HOST = localhost
Production Settings
For production, set environment variables through your hosting platform or use a secure secrets manager.
Production Setup Learn how to deploy Aqua-IoT in a production environment
Configuration Checklist
Before deploying to production: