diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py index f075182b9..059ee2a38 100644 --- a/gettingstarted/settings.py +++ b/gettingstarted/settings.py @@ -23,6 +23,15 @@ # Before using your Heroku app in production, make sure to review Django's deployment checklist: # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ +CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.redis.RedisCache", + "LOCATION": os.environ.get('REDIS_TLS_URL'), + "OPTIONS": { + } + } +} + # Django requires a unique secret key for each Django app, that is used by several of its # security features. To simplify initial setup (without hardcoding the secret in the source # code) we set this to a random value every time the app starts. However, this will mean many @@ -43,6 +52,7 @@ IS_HEROKU_APP = "DYNO" in os.environ and not "CI" in os.environ # SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True if not IS_HEROKU_APP: DEBUG = True diff --git a/hello/templates/index.html b/hello/templates/index.html index 55951ccc2..43171a089 100644 --- a/hello/templates/index.html +++ b/hello/templates/index.html @@ -1,5 +1,7 @@ {% extends "base.html" %} {% load static %} +{% load cache %} +{% cache 500 recipe %} {% block content %} @@ -56,3 +58,4 @@

Helpful Links

{% endblock %} +{% endcache %} diff --git a/hello/views.py b/hello/views.py index bd7a34b00..fc513ea1a 100644 --- a/hello/views.py +++ b/hello/views.py @@ -3,10 +3,15 @@ from .models import Greeting # Create your views here. +from django.views.decorators.cache import cache_page - +@cache_page(60 * 15) def index(request): - return render(request, "index.html") + try: + return render(request, "index.html") + except Exception as e: + return render(request, e) + def db(request): diff --git a/requirements.txt b/requirements.txt index ceeba6c2e..72c962557 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,11 +2,12 @@ django>=4.2,<5.0 gunicorn>=20.0,<21.0 dj-database-url>=2.0,<3.0 whitenoise[brotli]>=6.0,<7.0 +redis>=3.0.0 # Uncomment these lines to use a Postgres database. Both are needed, since in production # (which uses Linux) we want to install from source, so that security updates from the # underlying Heroku stack image are picked up automatically, thanks to dynamic linking. # On other platforms/in development, the precompiled binary package is used instead, to # speed up installation and avoid errors from missing libraries/headers. -#psycopg; sys_platform == "linux" -#psycopg[binary]; sys_platform != "linux" +psycopg; sys_platform == "linux" +psycopg[binary]; sys_platform != "linux"