ruk·si

🍡 Django Tutorial
Create Django App

Updated at 2018-11-23 18:16

Create "a Django app" (i.e. a feature set in your solution) named "polls": This "app" will focus on handling polls, the questions and voting.

python manage.py startapp polls

Edit polls/views.py:

from django.http import HttpResponse, HttpRequest


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

Create polls/urls.py:

from django.urls import path

from . import views

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

Edit djangor/urls.py. The include() function allows referencing route configurations of other installed apps in your Django project.

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

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

Try out your new app:

python manage.py runserver
# navigate to http://localhost:8000/polls/