-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdjango_example.py
More file actions
executable file
·91 lines (77 loc) · 2.5 KB
/
django_example.py
File metadata and controls
executable file
·91 lines (77 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""
Django integration example for allgreen health checks.
This is a minimal Django setup showing how to integrate allgreen.
Install dependencies:
pip install allgreen[django]
Setup:
1. Create a Django project: django-admin startproject myproject
2. Add this code to your urls.py and views.py
3. Or run this file directly for a minimal example
Run:
python examples/django_example.py
# Visit http://localhost:8000/healthcheck
"""
import os
# Minimal Django setup for this example
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '__main__')
# Django settings (inline for this example)
DEBUG = True
SECRET_KEY = 'django-example-key-not-for-production'
ROOT_URLCONF = '__main__'
USE_TZ = True
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.auth',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
],
},
},
]
if __name__ == '__main__':
import django
from django.conf import settings
from django.core.management import execute_from_command_line
from django.http import HttpResponse
from django.urls import path
# Configure Django
settings.configure(
DEBUG=DEBUG,
SECRET_KEY=SECRET_KEY,
ROOT_URLCONF=ROOT_URLCONF,
USE_TZ=USE_TZ,
INSTALLED_APPS=INSTALLED_APPS,
TEMPLATES=TEMPLATES,
)
django.setup()
# Import after Django setup
from allgreen.integrations.django_integration import healthcheck_view
# Views
def index(request):
return HttpResponse('''
<h1>Django + Allgreen Example</h1>
<p><a href="/healthcheck/">View Health Checks</a></p>
<p><a href="/healthcheck/?format=json">JSON API</a></p>
''')
# URL patterns
urlpatterns = [
path('', index),
path('healthcheck/', healthcheck_view, name='healthcheck'),
]
print("🚀 Django + Allgreen Example")
print("📋 Health checks: http://localhost:8000/healthcheck/")
print("🔧 JSON API: http://localhost:8000/healthcheck/?format=json")
print("💡 Using config: examples/allgreen_config.py")
print()
# Run Django dev server
execute_from_command_line(['manage.py', 'runserver', '8000'])