- 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 mysiteand the structure should then look like this
mysite
├── manage.py
└── mysite
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
1 directory, 5 filesStart the development server
Change directories into mysite by
cd mysitenow run the server
python3 manage.py runserverwhich 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 pollswhich 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 filespolls/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.pyNote the db.sqlite3 file that is present here, we’ll remove it and add Cloud Spanner in the next tutorials.