This is a sample Python application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.
-
-
- To deploy your own copy, and learn the fundamentals of the Heroku platform, head over to the
Getting Started with Python on Heroku tutorial.
+
+ To deploy your own copy, and learn the fundamentals of the Heroku platform, head over to either of the following tutorials:
+
-
+
How this sample app works
- - This app was deployed to Heroku, either using Git or by using Heroku Button on the repository.
-
- - When Heroku received the source code, it grabbed all the dependencies in the requirements.txt file.
- - The platform then spins up a dyno, a lightweight container that provides an isolated environment in which the slug can be mounted and executed.
+ - This app was deployed to Heroku using Git.
+ - When Heroku received the source code, it fetched all the dependencies in requirements.txt, creating a deployable build artifact.
+ - The platform then spins up a dyno, a lightweight container that provides an isolated environment in which the build artifact can be mounted and executed.
- You can scale your app, manage it, and deploy over 150 add-on services, from the Dashboard or CLI.
- - Check out the Getting Started guide to learn more!
+
Next Steps
+
Helpful Links
-
-
- Please do work through the Getting Started guide, even if you do know how to build such an application. The guide covers the basics of working with Heroku, and will familiarize you with all the concepts you need in order to build and deploy your own apps.
+
+
+
+
+ Please do work through the Getting Started guide, even if you do know how to build such an application. The guide covers the basics of working with Heroku, and will familiarize you with all the concepts you need in order to build and deploy your own apps.
+
+
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/hello/tests.py b/hello/tests.py
index 7ce503c2d..8134bff8b 100644
--- a/hello/tests.py
+++ b/hello/tests.py
@@ -1,3 +1,26 @@
from django.test import TestCase
# Create your tests here.
+
+
+# Note: The tests below rely upon static assets (for the rendered templates), so require that either:
+# 1. The static assets have been processed - ie: `./manage.py collectstatic` has been run.
+# 2. Or, the tests are run in debug mode (which means WhiteNoise will use auto-refresh mode),
+# using: `./manage.py test --debug-mode`
+class ExampleTest(TestCase):
+ def test_index_page(self):
+ response = self.client.get("/")
+ self.assertContains(
+ response, "Getting Started with Python on Heroku", status_code=200
+ )
+
+ def test_db_page(self):
+ # Each time the page is requested, the number of recorded greetings increases.
+
+ first_response = self.client.get("/db/")
+ self.assertEqual(first_response.status_code, 200)
+ self.assertEqual(len(first_response.context["greetings"]), 1)
+
+ second_response = self.client.get("/db/")
+ self.assertEqual(second_response.status_code, 200)
+ self.assertEqual(len(second_response.context["greetings"]), 2)
diff --git a/hello/views.py b/hello/views.py
index 8558d8451..bd7a34b00 100644
--- a/hello/views.py
+++ b/hello/views.py
@@ -1,20 +1,28 @@
from django.shortcuts import render
-from django.http import HttpResponse
from .models import Greeting
# Create your views here.
+
+
def index(request):
- # return HttpResponse('Hello from Python!')
- return render(request, 'index.html')
+ return render(request, "index.html")
def db(request):
+ # If you encounter errors visiting the `/db/` page on the example app, check that:
+ #
+ # When running the app on Heroku:
+ # 1. You have added the Postgres database to your app.
+ # 2. You have uncommented the `psycopg` dependency in `requirements.txt`, and the `release`
+ # process entry in `Procfile`, git committed your changes and re-deployed the app.
+ #
+ # When running the app locally:
+ # 1. You have run `./manage.py migrate` to create the `hello_greeting` database table.
greeting = Greeting()
greeting.save()
greetings = Greeting.objects.all()
- return render(request, 'db.html', {'greetings': greetings})
-
+ return render(request, "db.html", {"greetings": greetings})
diff --git a/manage.py b/manage.py
index eb3ab8af5..34a1c557c 100755
--- a/manage.py
+++ b/manage.py
@@ -1,10 +1,23 @@
#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+
import os
import sys
-if __name__ == "__main__":
+
+def main():
+ """Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings")
+ try:
+ from django.core.management import execute_from_command_line
+ except ImportError as exc:
+ raise ImportError(
+ "Couldn't import Django. Are you sure it's installed and "
+ "available on your PYTHONPATH environment variable? Did you "
+ "forget to activate a virtual environment?"
+ ) from exc
+ execute_from_command_line(sys.argv)
- from django.core.management import execute_from_command_line
- execute_from_command_line(sys.argv)
+if __name__ == "__main__":
+ main()
diff --git a/project.toml b/project.toml
new file mode 100644
index 000000000..ec4f08cbd
--- /dev/null
+++ b/project.toml
@@ -0,0 +1,19 @@
+[_]
+schema-version = "0.2"
+
+[io.buildpacks]
+# Exclude files from local Pack CLI builds, where .gitignore doesn't apply.
+# TODO: Add trailing slash to entries that are directories, once this issue is fixed:
+# https://github.com/buildpacks/pack/issues/2402
+exclude = [
+ "__pycache__",
+ ".git",
+ ".gitignore",
+ ".github",
+ ".venv",
+ ".DS_Store",
+ ".env",
+ "staticfiles",
+ "db.sqlite3",
+ "venv",
+]
diff --git a/requirements.txt b/requirements.txt
index 5ced65136..db5f46b0f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,7 @@
-dj-database-url==0.4.0
-Django==1.9.2
-gunicorn==19.4.5
-psycopg2==2.6.1
-whitenoise==2.0.6
+django>=6.1,<6.2
+gunicorn>=26,<27
+dj-database-url>=3,<4
+whitenoise>=6,<7
+
+# Uncomment to use a Postgres database.
+#psycopg[binary]
diff --git a/runtime.txt b/runtime.txt
deleted file mode 100644
index 0239feabb..000000000
--- a/runtime.txt
+++ /dev/null
@@ -1 +0,0 @@
-python-2.7.11