Skip to content

Creating the “polls” Django app


From the online documentation…

Projects vs Apps: An app is a web application that does something, a project is a collection of configuration and apps. A project can contain multiple apps and an app can be in multiple projects.

Apps can live anywhere on the Python path.

Creating the polls app

1) Create the app
navigate to same direcotry as
cd C:\Users\john.knight\OneDrive\Django\mysite

python startapp polls

This creates the poll directory with the following content:

2) Create the first view
Open polls\ in an editor and enter the following code so that the file looks like:

from django.http import HttpResponse

def index(request):
return HttpResponse(“Hello, world. This is the polls index.”)

To call this view, it needs to be mapped to a URL by using a URLconf.

3) Create the URLconf
Create a file called in the polls directory.

With an editor, add the following code to

from django.conf.urls import url

from . import views

urlpatterns = [
  url(r’^$’, views.index, name=’index’),

4) Point URLconf at rool level to the polls.urls module.
Navigate to the mysites directory.
cd C:\Users\john.knight\OneDrive\Django\mysite\mysite

Amend the existing contents of so that it looks like this:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
  url(r’^polls/’, include(‘polls.urls’)),

5) Test it works
Navigate to the mysite container directory
cd C:\Users\john.knight\OneDrive\Django\mysite

python runserver

Browse to

You should now see the message “Hello, world. You’re at the polls index.” displayed in the brwoser.


From → Development

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: