Skip to content

Commit 262f460

Browse files
author
Adios Template Bot
committed
Sync template-python-django from canonical templates
Template-Source-Digest: sha256:0725c638f3755e5d4499a1ac8439f1c25731af91dd82038a75c756206156afd9
0 parents  commit 262f460

12 files changed

Lines changed: 435 additions & 0 deletions

File tree

‎.editorconfig‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.{js,jsx,ts,tsx,css,scss,less,html,json,yml,yaml}]
12+
indent_size = 2
13+
14+
[*.md]
15+
indent_size = 2
16+
trim_trailing_whitespace = false
17+
18+
[*.sh]
19+
indent_size = 2
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Validate template
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
template:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
15+
- name: Check repository contract
16+
shell: bash
17+
run: |
18+
set -euo pipefail
19+
test -s README.md
20+
test -s adios.yaml
21+
test -s .gitignore
22+
test -s .editorconfig
23+
grep -q "adios up" README.md
24+
ruby -e 'require "yaml"; content = File.read("adios.yaml"); value = begin; YAML.safe_load(content, permitted_classes: [], permitted_symbols: [], aliases: true); rescue ArgumentError; YAML.safe_load(content, [], [], true); end; abort "adios.yaml must contain a mapping" unless value.is_a?(Hash)'
25+
if git ls-files \
26+
| grep -E '(^|/)(node_modules|\.next|dist|build|bin|obj|out|vendor|\.venv|__pycache__|\.pytest_cache|\.mypy_cache|\.ruff_cache|coverage|staticfiles)(/|$)|\.py[co]$' \
27+
| grep -Ev '^bin/rails$' \
28+
| grep -q .; then
29+
echo "Generated dependencies or build output are tracked" >&2
30+
exit 1
31+
fi

‎.gitignore‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# OS files
2+
.DS_Store
3+
Thumbs.db
4+
5+
# Environment and secrets
6+
.env
7+
.env.*
8+
!.env.example
9+
*.key
10+
*.pem
11+
*.crt
12+
13+
# Logs
14+
*.log
15+
logs/
16+
npm-debug.log*
17+
yarn-debug.log*
18+
yarn-error.log*
19+
.pnpm-debug.log*
20+
21+
# Dependencies
22+
node_modules/
23+
.pnp/
24+
.pnp.*
25+
vendor/
26+
.venv/
27+
venv/
28+
env/
29+
30+
# Build output and caches
31+
.next/
32+
out/
33+
dist/
34+
build/
35+
coverage/
36+
.pytest_cache/
37+
.mypy_cache/
38+
.ruff_cache/
39+
__pycache__/
40+
*.py[cod]
41+
staticfiles/
42+
bin/
43+
obj/
44+
TestResults/
45+
*.tsbuildinfo
46+
next-env.d.ts
47+
48+
# Runtime data
49+
data/
50+
tmp/
51+
*.pid

‎README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Python Django Template
2+
3+
Production-oriented Django starter for Adios.
4+
5+
## Deploy
6+
7+
```sh
8+
adios up
9+
```
10+
11+
## Configuration
12+
13+
* **Runtime:** `python@3.13`
14+
* **Build:** Installs dependencies, then collects static assets from `backend/`
15+
* **Release:** Declares migrations as a separate release command
16+
* **Start:** Runs Gunicorn from `backend/` and binds to `${PORT:-8080}`
17+
* **Health:** Verifies both Django and PostgreSQL with a read-only `SELECT 1`
18+
19+
## Notes
20+
21+
* The Django project root is `backend/`
22+
* `DJANGO_SETTINGS_MODULE` is set to `backend.settings`
23+
* Worker count and worker class can be adjusted with `GUNICORN_WORKERS` and `GUNICORN_WORKER_CLASS`

‎adios.yaml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
type: web
2+
runtime:
3+
name: python@3.13
4+
health_path: /healthz
5+
readiness_timeout_seconds: 120
6+
secrets:
7+
DJANGO_SECRET_KEY: secret://generate:64
8+
POSTGRES_PASSWORD: secret://generate:32
9+
resources:
10+
db:
11+
template: postgres:16
12+
type: database
13+
database: django
14+
username: django
15+
password: secret://POSTGRES_PASSWORD
16+
dependency_cmd: python -m pip install -r requirements.txt
17+
build_cmd: |
18+
python manage.py collectstatic --noinput
19+
release_cmd: python manage.py migrate --noinput
20+
start_cmd: |
21+
python -m gunicorn backend.wsgi:application --bind 0.0.0.0:${PORT:-8080} --workers ${GUNICORN_WORKERS:-2} --worker-class ${GUNICORN_WORKER_CLASS:-gevent}
22+
env:
23+
PORT: "8080"
24+
PYTHONUNBUFFERED: "1"
25+
DJANGO_SETTINGS_MODULE: backend.settings
26+
DJANGO_SECRET_KEY: secret://DJANGO_SECRET_KEY
27+
DATABASE_URL: secret://DATABASE_URL
28+
GUNICORN_WORKERS: "2"
29+
GUNICORN_WORKER_CLASS: gevent

‎backend/__init__.py‎

Whitespace-only changes.

‎backend/asgi.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for backend project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
15+
16+
application = get_asgi_application()

‎backend/settings.py‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""
2+
Django settings for backend project.
3+
4+
Generated by 'django-admin startproject' using Django 6.0.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/6.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/6.0/ref/settings/
11+
"""
12+
13+
import os
14+
from pathlib import Path
15+
from urllib.parse import urlparse
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = os.getenv(
26+
"DJANGO_SECRET_KEY",
27+
"django-insecure-21r+^amj1kaovh#%uvz22%wa_2luw92q51fe$3_q%@f9*ijb--",
28+
)
29+
30+
# SECURITY WARNING: don't run with debug turned on in production!
31+
DEBUG = os.getenv("DJANGO_DEBUG", "").lower() in {"1", "true", "yes", "on"}
32+
33+
ALLOWED_HOSTS = [
34+
host.strip()
35+
for host in os.getenv("DJANGO_ALLOWED_HOSTS", "*").split(",")
36+
if host.strip()
37+
]
38+
39+
40+
# Application definition
41+
42+
INSTALLED_APPS = [
43+
"django.contrib.admin",
44+
"django.contrib.auth",
45+
"django.contrib.contenttypes",
46+
"django.contrib.sessions",
47+
"django.contrib.messages",
48+
"django.contrib.staticfiles",
49+
]
50+
51+
MIDDLEWARE = [
52+
"django.middleware.security.SecurityMiddleware",
53+
"django.contrib.sessions.middleware.SessionMiddleware",
54+
"django.middleware.common.CommonMiddleware",
55+
"django.middleware.csrf.CsrfViewMiddleware",
56+
"django.contrib.auth.middleware.AuthenticationMiddleware",
57+
"django.contrib.messages.middleware.MessageMiddleware",
58+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
59+
]
60+
61+
ROOT_URLCONF = "backend.urls"
62+
63+
TEMPLATES = [
64+
{
65+
"BACKEND": "django.template.backends.django.DjangoTemplates",
66+
"DIRS": [],
67+
"APP_DIRS": True,
68+
"OPTIONS": {
69+
"context_processors": [
70+
"django.template.context_processors.request",
71+
"django.contrib.auth.context_processors.auth",
72+
"django.contrib.messages.context_processors.messages",
73+
],
74+
},
75+
},
76+
]
77+
78+
WSGI_APPLICATION = "backend.wsgi.application"
79+
80+
81+
# Database
82+
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
83+
84+
database_url = os.getenv("DATABASE_URL", "").strip()
85+
if database_url.startswith(("postgres://", "postgresql://")):
86+
parsed = urlparse(database_url)
87+
DATABASES = {
88+
"default": {
89+
"ENGINE": "django.db.backends.postgresql",
90+
"NAME": parsed.path.lstrip("/") or "postgres",
91+
"USER": parsed.username or "",
92+
"PASSWORD": parsed.password or "",
93+
"HOST": parsed.hostname or "",
94+
"PORT": parsed.port or 5432,
95+
}
96+
}
97+
else:
98+
DATABASES = {
99+
"default": {
100+
"ENGINE": "django.db.backends.sqlite3",
101+
"NAME": Path("/app/data/db.sqlite3"),
102+
}
103+
}
104+
105+
106+
# Password validation
107+
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
108+
109+
AUTH_PASSWORD_VALIDATORS = [
110+
{
111+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
112+
},
113+
{
114+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
115+
},
116+
{
117+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
118+
},
119+
{
120+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
121+
},
122+
]
123+
124+
125+
# Internationalization
126+
# https://docs.djangoproject.com/en/6.0/topics/i18n/
127+
128+
LANGUAGE_CODE = "en-us"
129+
130+
TIME_ZONE = "UTC"
131+
132+
USE_I18N = True
133+
134+
USE_TZ = True
135+
136+
137+
# Static files (CSS, JavaScript, Images)
138+
# https://docs.djangoproject.com/en/6.0/howto/static-files/
139+
140+
STATIC_URL = "static/"
141+
STATIC_ROOT = BASE_DIR / "staticfiles"

‎backend/urls.py‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
URL configuration for backend project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/6.0/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.contrib import admin
19+
from django.db import connection
20+
from django.http import HttpResponse, JsonResponse
21+
from django.urls import path
22+
23+
HTML = """<!doctype html>
24+
<html lang="en">
25+
<head>
26+
<meta charset="utf-8">
27+
<meta name="viewport" content="width=device-width, initial-scale=1">
28+
<title>Hello from Adios</title>
29+
<style>
30+
body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Arial, sans-serif; color: #f8fafc; background: #020617; }
31+
main { width: min(680px, calc(100% - 48px)); }
32+
p.kicker { color: #67e8f9; font-weight: 700; letter-spacing: .24em; text-transform: uppercase; }
33+
h1 { margin: 16px 0; font-size: clamp(3rem, 9vw, 5.5rem); line-height: 1; }
34+
p { color: #cbd5e1; font-size: 1.125rem; line-height: 1.7; }
35+
nav { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }
36+
a { border: 1px solid rgba(255,255,255,.18); border-radius: 8px; color: #f8fafc; padding: 12px 16px; text-decoration: none; }
37+
a.primary { background: #67e8f9; color: #020617; border-color: #67e8f9; font-weight: 700; }
38+
</style>
39+
</head>
40+
<body>
41+
<main>
42+
<p class="kicker">Adios starter</p>
43+
<h1>Hello from Adios</h1>
44+
<p>This Django template is ready to build, ship, and run on Adios.</p>
45+
<nav aria-label="Adios links">
46+
<a class="primary" href="https://app.adios.dev/signup">Deploy on Adios</a>
47+
<a href="https://www.adios.dev/docs/quickstart">Read the quickstart</a>
48+
</nav>
49+
</main>
50+
</body>
51+
</html>
52+
"""
53+
54+
55+
def home(_request):
56+
return HttpResponse(HTML)
57+
58+
59+
def healthz(_request):
60+
with connection.cursor() as cursor:
61+
cursor.execute("SELECT 1")
62+
cursor.fetchone()
63+
return JsonResponse(
64+
{"ok": True},
65+
json_dumps_params={"separators": (",", ":")},
66+
)
67+
68+
69+
urlpatterns = [
70+
path("", home, name="home"),
71+
path("healthz", healthz, name="healthz"),
72+
path("admin/", admin.site.urls),
73+
]

0 commit comments

Comments
 (0)