We'll need a simple Django app to demonstrate the Zappa functionality.
Establish a virtual environment and install packages#
We will run most of the commands in our Docker instance so that all packages installed will be appropriate for the AWS Lambda environment. If you run these commands on your local system, you may install versions of the package that will fail when executed in the cloud. Start your Docker instance by running on Mac or Linux:
./zappashell.sh
Or if you're on Windows:
zappashell.bat
You should see the zappashell>
prompt.
Now create a virtual environment, activate it, and install Django & Zappa. Note we are calling the virtual environment ve
. Note the command prompt will change to indicate that the virtual environment is active.
zappashell> virtualenv ve
zappashell> source ve/bin/active
(ve) zappashell> pip install django zappa
One of the nice things about running in Docker is that any Python build / compiling is done using a near-Lambda environment. This allows us to be confident that our app will work fine when in production.
Start a Django Project#
We'll call our simple project 'Frankie.' To have the Django Admin generate code for the Django project, simply run:
(ve) zappashell> django-admin startproject frankie .
And now let's run it on our local system to see if it's working. Note that we are running the Django project within the Docker instance.
(ve) zappashell> python manage.py runserver 0:8000
This is the common Django runserver command to launch a small web server so we can debug our Django application. There's a slight difference from the typical usage you may have seen: we have added 0:8000
to the runserver command. This is because we're running in a virtual environment and this enables the debug server to be seen by the host system. If you omit this portion of the command line, you won't be able to use the browser on your local machine to view the page.
Now, point your browser at http://localhost:8000. You should see the default Django page.
SQLite Error!!#
Uh-oh! Actually, we don't see the default Django page - we see a bunch of errors that should end with something like this:
File "/var/task/ve/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 67, in check_sqlite_version
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
Bummer. This is caused by the fact that most Python installations bundle SQLite, a helpful library that lets you run a little database locally. However, the AWS Lambda version of Python does not include this library. Fortunately, we won't need SQLite for this course, so we have to comment out some lines in our Django settings. Edit the file frankie\settings.py
and comment out the DATABASES
lines:
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
""" Comment out this section for now
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
"""
Don't worry - we'll add back database support in the Module about Databases. For now, we're just getting this up and running locally.
Try again#
Now point your browser at http://localhost:8000. You should see the default Django page.

First view#
Now let's create a simple view to power this Django app so it's a little more interesting than the default view. Run the following command to add a Django application to the project:
(ve) zappashell> python manage.py startapp guitar
Edit guitar/views.py
to create a view that sends a brief greeting:
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. Who loves Django?")
Edit guitar/urls.py
to wire up the new view we created:
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
Edit frankie/urls.py
to add the guitar
Django application:
"""frankie URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("", include("guitar.urls")),
path("admin/", admin.site.urls),
]
Refresh#
Now refresh your browser and you should see our message in the browser window

Cool, huh? In the next lesson, we will get this loaded in the cloud!