First django app

Posted under » Django on 29 April 2021

This is from the official django polls app tutorial v.3.2 but I make it shorter and adjust it to my taste. I testing it with version 3.15 and it worked for me except for the The display decorator part.

You start the polls app by

$ python startapp polls

It will create a few files. Next we create a view by editing the file which is the index file.

from django.http import HttpResponse

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

We assign the the url to the view by creating a url file 'polls/'

from django.urls import path

from . import views

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

The next step is to point the root URLconf at the polls.urls module. In mysite/, add an import for django.urls.include and insert an include() in the urlpatterns list, so you have:

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

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

If for some reason, you don't see the http://mysite/polls/ you have to restart daemon and apache. Next we create Django models using migrate.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS