spanner-django logo spanner-django

☰
  • Install
  • Quickstart
    • From scratch
      • Tutorial 1
      • Tutorial 2
    • Existing apps
  • FAQ
Navigation :
  • Requirements
  • Create your Django project
  • Start the development server
  • Create the Polls app
  • polls/view.py
  • polls/urls.py
  • mysite/urls.py

Following steps at Django 1

Requirements

Please ensure that you’ve followed the Install step

Create your project

django-admin startproject mysite

and the structure should then look like this

mysite
├── manage.py
└── mysite
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

1 directory, 5 files

Start the development server

Change directories into mysite by

cd mysite

now run the server

python3 manage.py runserver

which should produce

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

November 25, 2019 - 15:50:53
Django version 2.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Create the Polls app

Following the polls app creation, we’ll go ahead and create an app

python3 manage.py startapp polls

which will create a directory polls, laid out as follows

polls
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│   └── __init__.py
├── models.py
├── tests.py
└── views.py

1 directory, 7 files

polls/views.py

We’ll create the first view, by editing the file polls/view.py

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, Cloud Spanner. You're at the polls index.")

polls/urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

mysite/urls.py

Edit the mysite/urls.py file to

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

and now the current working directory should look like this

.
├── db.sqlite3
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── polls
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    ├── urls.py
    └── views.py

Note the db.sqlite3 file that is present here, we’ll remove it and add Cloud Spanner in the next tutorials.

Edit this page on Github
  • Github
spanner-django