Django 1.11.17 Tutorial (part2) – Create Polls App

In part 1 (Create a Django 1.11.17 Environment) of this django tutorial how to create a django webapp, I set up a Django 1.11.17 project in PyCharm. In this post, I will set up and configure the polls application. This is the start of creating a first django webapp.

Create Polls App In PyCharm

  • Launch PyCharm
  • Click on Tools->run manage.py Task
  • In the manage.py console, type startapp polls

views.py, polls\urls.py, mysite\urls.py

See the official django polls tutorial for more.Otherwise just add the following code into the following files:

   polls\views.py


from django.http import HttpResponse

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

   polls\urls.py


from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^$', views.index, name='index'),
]

   mysite\urls.py


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

urlpatterns = [
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', admin.site.urls),
]

Runserver

Again, do menu->Tools->Run manage.py Task, then call runserver in the manage.py console (if the server isn’t already running).

Enter “http://127.0.0.1:8000/polls/” and you should see “Hello, world. You’re at the polls index.”

Pin It on Pinterest

Share This