Skip to content

Commit e81b1a2

Browse files
committed
Heroku Integration
1 parent 4e76235 commit e81b1a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+689
-1101
lines changed

backend/.github/CODEOWNERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Note: Delete this file if you are copying the code in this repository into your own project.
2+
3+
# Default to requesting pull request reviews from the Heroku Languages team.
4+
* @heroku/languages
5+
6+
# However, request review from the Heroku language owner for files that are updated
7+
# by Dependabot, to reduce team review request noise.
8+
requirements.txt @edmorley
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- Hi and welcome to the Heroku Python Getting Started repository!
2+
3+
This Django project is meant to be a starting point for other projects.
4+
5+
If you meant to open a PR against a fork instead of upstream, please adjust the base branch:
6+
https://help.github.com/articles/changing-the-base-branch-of-a-pull-request/
7+
8+
Otherwise thank you in advance for your Pull Request - just remember to
9+
include as much information as possible to help the reviewers :-)
10+
-->

backend/.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"

backend/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Python files
2+
__pycache__/
3+
.venv/
4+
venv/
5+
6+
# Django files
7+
staticfiles/
8+
db.sqlite3
9+
10+
# macOS files
11+
.DS_Store

backend/Procfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
web: gunicorn your_script_name:app
1+
web: gunicorn gettingstarted.wsgi --log-file -
2+
3+
# Uncomment this `release` process if you are using a database, so that Django's model
4+
# migrations are run as part of app deployment, using Heroku's Release Phase feature:
5+
# https://docs.djangoproject.com/en/5.0/topics/migrations/
6+
# https://devcenter.heroku.com/articles/release-phase
7+
release: ./manage.py migrate --no-input

backend/Procfile.windows

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python manage.py runserver %PORT%

backend/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
This is the backend for NovaSystem. It is a simple API that allows you to interact with the NovaSystem from the frontend.
1+
# Python: Getting Started
2+
3+
A barebones Django app, which can easily be deployed to Heroku.
4+
5+
## Deploying to Heroku
6+
7+
Using resources for this example app counts towards your usage. [Delete your app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy) and [database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) as soon as you are done experimenting to control costs.
8+
9+
By default, apps use Eco dynos if you are subscribed to Eco. Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Learn more about our low-cost plans [here](https://blog.heroku.com/new-low-cost-plans).
10+
11+
Eligible students can apply for platform credits through our new [Heroku for GitHub Students program](https://blog.heroku.com/github-student-developer-program).
12+
13+
This application supports the [Getting Started with Python on Heroku](https://devcenter.heroku.com/articles/getting-started-with-python) article - check it out for instructions on how to deploy this app to Heroku and also run it locally.
14+
15+
Alternatively, you can deploy it using this Heroku Button:
16+
17+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://www.heroku.com/deploy?template=https://github.com/heroku/python-getting-started)
18+
19+
For more information about using Python on Heroku, see these Dev Center articles:
20+
21+
- [Python on Heroku](https://devcenter.heroku.com/categories/python)

backend/app.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Start on Heroku: Python",
3+
"description": "A barebones Python app, which can easily be deployed to Heroku.",
4+
"image": "heroku/python",
5+
"repository": "https://github.com/heroku/python-getting-started",
6+
"keywords": ["python", "django"],
7+
"env": {
8+
"DJANGO_SECRET_KEY": {
9+
"description": "The secret key for the Django application.",
10+
"generator": "secret"
11+
}
12+
},
13+
"environments": {
14+
"test": {
15+
"scripts": {
16+
"test": "./manage.py test --debug-mode"
17+
}
18+
}
19+
}
20+
}

backend/gettingstarted/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 gettingstarted 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/5.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", "gettingstarted.settings")
15+
16+
application = get_asgi_application()

backend/gettingstarted/settings.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
"""
2+
Django settings for gettingstarted project.
3+
4+
Generated by 'django-admin startproject' using Django 5.0.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.0/ref/settings/
11+
"""
12+
13+
import os
14+
import secrets
15+
from pathlib import Path
16+
17+
import dj_database_url
18+
19+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
20+
BASE_DIR = Path(__file__).resolve().parent.parent
21+
22+
23+
# Before using your Heroku app in production, make sure to review Django's deployment checklist:
24+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
25+
26+
# Django requires a unique secret key for each Django app, that is used by several of its
27+
# security features. To simplify initial setup (without hardcoding the secret in the source
28+
# code) we set this to a random value every time the app starts. However, this will mean many
29+
# Django features break whenever an app restarts (for example, sessions will be logged out).
30+
# In your production Heroku apps you should set the `DJANGO_SECRET_KEY` config var explicitly.
31+
# Make sure to use a long unique value, like you would for a password. See:
32+
# https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-SECRET_KEY
33+
# https://devcenter.heroku.com/articles/config-vars
34+
# SECURITY WARNING: keep the secret key used in production secret!
35+
SECRET_KEY = os.environ.get(
36+
"DJANGO_SECRET_KEY",
37+
default=secrets.token_urlsafe(nbytes=64),
38+
)
39+
40+
# The `DYNO` env var is set on Heroku CI, but it's not a real Heroku app, so we have to
41+
# also explicitly exclude CI:
42+
# https://devcenter.heroku.com/articles/heroku-ci#immutable-environment-variables
43+
IS_HEROKU_APP = "DYNO" in os.environ and not "CI" in os.environ
44+
45+
# SECURITY WARNING: don't run with debug turned on in production!
46+
if not IS_HEROKU_APP:
47+
DEBUG = True
48+
49+
# On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS``, since the Heroku router performs
50+
# validation of the Host header in the incoming HTTP request. On other platforms you may need to
51+
# list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See:
52+
# https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-ALLOWED_HOSTS
53+
if IS_HEROKU_APP:
54+
ALLOWED_HOSTS = ["*"]
55+
else:
56+
ALLOWED_HOSTS = [".localhost", "127.0.0.1", "[::1]", "0.0.0.0"]
57+
58+
59+
# Application definition
60+
61+
INSTALLED_APPS = [
62+
# Use WhiteNoise's runserver implementation instead of the Django default, for dev-prod parity.
63+
"whitenoise.runserver_nostatic",
64+
# Uncomment this and the entry in `urls.py` if you wish to use the Django admin feature:
65+
# https://docs.djangoproject.com/en/5.0/ref/contrib/admin/
66+
# "django.contrib.admin",
67+
"django.contrib.auth",
68+
"django.contrib.contenttypes",
69+
"django.contrib.sessions",
70+
"django.contrib.messages",
71+
"django.contrib.staticfiles",
72+
"hello",
73+
]
74+
75+
MIDDLEWARE = [
76+
"django.middleware.security.SecurityMiddleware",
77+
# Django doesn't support serving static assets in a production-ready way, so we use the
78+
# excellent WhiteNoise package to do so instead. The WhiteNoise middleware must be listed
79+
# after Django's `SecurityMiddleware` so that security redirects are still performed.
80+
# See: https://whitenoise.readthedocs.io
81+
"whitenoise.middleware.WhiteNoiseMiddleware",
82+
"django.contrib.sessions.middleware.SessionMiddleware",
83+
"django.middleware.common.CommonMiddleware",
84+
"django.middleware.csrf.CsrfViewMiddleware",
85+
"django.contrib.auth.middleware.AuthenticationMiddleware",
86+
"django.contrib.messages.middleware.MessageMiddleware",
87+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
88+
]
89+
90+
ROOT_URLCONF = "gettingstarted.urls"
91+
92+
TEMPLATES = [
93+
{
94+
"BACKEND": "django.template.backends.django.DjangoTemplates",
95+
"DIRS": [],
96+
"APP_DIRS": True,
97+
"OPTIONS": {
98+
"context_processors": [
99+
"django.template.context_processors.debug",
100+
"django.template.context_processors.request",
101+
"django.contrib.auth.context_processors.auth",
102+
"django.contrib.messages.context_processors.messages",
103+
],
104+
},
105+
},
106+
]
107+
108+
WSGI_APPLICATION = "gettingstarted.wsgi.application"
109+
110+
111+
# Database
112+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
113+
114+
if IS_HEROKU_APP:
115+
# In production on Heroku the database configuration is derived from the `DATABASE_URL`
116+
# environment variable by the dj-database-url package. `DATABASE_URL` will be set
117+
# automatically by Heroku when a database addon is attached to your Heroku app. See:
118+
# https://devcenter.heroku.com/articles/provisioning-heroku-postgres#application-config-vars
119+
# https://github.com/jazzband/dj-database-url
120+
DATABASES = {
121+
"default": dj_database_url.config(
122+
env="DATABASE_URL",
123+
conn_max_age=600,
124+
conn_health_checks=True,
125+
ssl_require=True,
126+
),
127+
}
128+
else:
129+
# When running locally in development or in CI, a sqlite database file will be used instead
130+
# to simplify initial setup. Longer term it's recommended to use Postgres locally too.
131+
DATABASES = {
132+
"default": {
133+
"ENGINE": "django.db.backends.sqlite3",
134+
"NAME": BASE_DIR / "db.sqlite3",
135+
}
136+
}
137+
138+
139+
# Password validation
140+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
141+
142+
AUTH_PASSWORD_VALIDATORS = [
143+
{
144+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
145+
},
146+
{
147+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
148+
},
149+
{
150+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
151+
},
152+
{
153+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
154+
},
155+
]
156+
157+
158+
# Internationalization
159+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
160+
161+
LANGUAGE_CODE = "en-us"
162+
163+
TIME_ZONE = "UTC"
164+
165+
USE_I18N = True
166+
167+
USE_TZ = True
168+
169+
170+
# Static files (CSS, JavaScript, Images)
171+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
172+
173+
STATIC_ROOT = BASE_DIR / "staticfiles"
174+
STATIC_URL = "static/"
175+
176+
STORAGES = {
177+
# Enable WhiteNoise's GZip and Brotli compression of static assets:
178+
# https://whitenoise.readthedocs.io/en/latest/django.html#add-compression-and-caching-support
179+
"staticfiles": {
180+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
181+
},
182+
}
183+
184+
# Don't store the original (un-hashed filename) version of static files, to reduce slug size:
185+
# https://whitenoise.readthedocs.io/en/latest/django.html#WHITENOISE_KEEP_ONLY_HASHED_FILES
186+
WHITENOISE_KEEP_ONLY_HASHED_FILES = True
187+
188+
189+
# Default primary key field type
190+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
191+
192+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

backend/gettingstarted/urls.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
URL configuration for gettingstarted project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.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+
# from django.contrib import admin
18+
from django.urls import path
19+
20+
import hello.views
21+
22+
urlpatterns = [
23+
path("", hello.views.index, name="index"),
24+
path("db/", hello.views.db, name="db"),
25+
# Uncomment this and the entry in `INSTALLED_APPS` if you wish to use the Django admin feature:
26+
# https://docs.djangoproject.com/en/5.0/ref/contrib/admin/
27+
# path("admin/", admin.site.urls),
28+
path('echo/', hello.views.echo, name='echo'),
29+
30+
]

backend/gettingstarted/wsgi.py

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

backend/hello/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

backend/hello/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class HelloConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "hello"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 5.0 on 2023-12-07 15:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
initial = True
8+
9+
dependencies = []
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name="Greeting",
14+
fields=[
15+
(
16+
"id",
17+
models.BigAutoField(
18+
auto_created=True,
19+
primary_key=True,
20+
serialize=False,
21+
verbose_name="ID",
22+
),
23+
),
24+
(
25+
"when",
26+
models.DateTimeField(
27+
auto_now_add=True, verbose_name="date created"
28+
),
29+
),
30+
],
31+
),
32+
]

0 commit comments

Comments
 (0)