Get started with django-activitylog-jwt today to bolster the security and audit capabilities of your Django application while leveraging the power of JWT authentication.
Project description
Django Activity Log: Track User Actions and Requests
Introduction
The Django Activity Log package provides a comprehensive solution for logging various activities within your Django application, including user actions, request events, model changes (CRUD operations), and authentication events. This logging capability is essential for security audits, compliance requirements, debugging, and gaining insights into user behavior.
Installation
- Install the package via pip:
pip install django_activitylog_jwt
- Add 'activitylog' to your INSTALLED_APPS list in settings.py:
INSTALLED_APPS = [
# ... other apps
'activitylog',
]
- Add 'activitylog.middleware.middleware.ActivityLogMiddleware' to your MIDDLEWARE list in settings.py:
MIDDLEWARE = [
# ... other middleware
'activitylog.middleware.middleware.ActivityLogMiddleware',
]
- (Optional) If you are using CORS (Cross-Origin Resource Sharing), add 'x-frontend-url' to your CORS_ALLOW_HEADERS list in settings.py to capture the frontend URL in request events:
CORS_ALLOW_HEADERS = [
'x-frontend-url',
# ... other headers
]
Frontend Integration (Optional but Recommended)
To capture the frontend URL for request event logging, include the following JavaScript code in your frontend:
const frontendUrl = window.location.href;
fetch('your-api-endpoint', {
method: 'GET', // or 'POST', 'PUT', etc.
headers: {
'X-Frontend-URL': frontendUrl,
'Content-Type': 'application/json' // Example of another header
// Add more headers as needed
},
// Add body for POST or PUT requests if required
})
.then(response => {
// Handle response
})
.catch(error => {
// Handle errors
});
Configuration (Optional)
Customize the behavior of the Activity Log using settings in settings.py:
settings.py
DJANGO_ACTIVITY_LOG_WATCH_AUTH_EVENTS = True
DJANGO_ACTIVITY_LOG_WATCH_MODEL_EVENTS = True
DJANGO_ACTIVITY_LOG_WATCH_REQUEST_EVENTS = True
DJANGO_ACTIVITY_LOG_WATCH_CORS_EVENTS = True
DJANGO_ACTIVITY_LOG_REMOTE_ADDR_HEADER = 'REMOTE_ADDR' # Default header containing client's IP address
DJANGO_ACTIVITY_LOG_BROWSER = 'User-Agent' # Optional: Customize the header containing browser information
DJANGO_ACTIVITY_LOG_PLATFORM = 'Platform' # Optional: Customize the header containing platform information
DJANGO_ACTIVITY_LOG_OPERATING_SYSTEM = 'OS' # Optional: Customize the header containing operating system information
DJANGO_ACTIVITY_LOG_USER_DB_CONSTRAINT = True # Optional: Control user deletion behavior (default: True to prevent deletion)
DJANGO_ACTIVITY_LOG_LOGGING_BACKEND = 'activitylog.backends.ModelBackend' # Set the logging backend (default: activitylog.backends.ModelBackend)
DJANGO_ACTIVITY_LOG_UNREGISTERED_CLASSES_DEFAULT = [] # Define models to exclude from logging (default: empty)
DJANGO_ACTIVITY_LOG_REGISTERED_CLASSES = [] # Define models to include explicitly (overrides default behavior)
DJANGO_ACTIVITY_LOG_UNREGISTERED_URLS_DEFAULT = ['/admin/', '/static/'] # Define URLs to exclude from logging
DJANGO_ACTIVITY_LOG_REGISTERED_URLS = [] # Define URLs to include explicitly (overrides default behavior)
DJANGO_ACTIVITY_LOG_ADMIN_SHOW_MODEL_EVENTS = True # Show model events in Django Admin (default: True)
DJANGO_ACTIVITY_LOG_ADMIN_SHOW_AUTH_EVENTS = True # Show authentication events in Django Admin (default: True)
DJANGO_ACTIVITY_LOG_ADMIN_SHOW_REQUEST_EVENTS = True # Show request events in Django Admin (default: True)
DJANGO_ACTIVITY_LOG_ADMIN_SHOW_CORS_EVENTS = True # Show CORS events in Django Admin (default: True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_activitylog_jwt-1.0.2.tar.gz
.
File metadata
- Download URL: django_activitylog_jwt-1.0.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff935f85a92ff39c85ad59118b394f6675bfad831cc4cab66cff1d16a5a8c37e |
|
MD5 | ea3a4fc6a95dc0c1743c87bb7497ddf5 |
|
BLAKE2b-256 | 11d14e679fae479c84c3ed3291d17002eff01e9588aaa8fb29fcf6fffd4fd325 |
File details
Details for the file django_activitylog_jwt-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: django_activitylog_jwt-1.0.2-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c2cd6607b42c8753139e853259a134bd7e8258f49fd9b0988f8028ae65cb1c4 |
|
MD5 | 1394d016423187ebef5512729367e4af |
|
BLAKE2b-256 | 197e295e06e27a6c49d10f52ac57b5191fef7655f1f5307bc31270a6a78021e2 |