UNC BACS 350

Web Apps with Python/Django

Logo

Lesson 4 - App Structure

LEARN

Today's Agenda

Command line

Tools

templates

views.py

urls.py

BUILD

Setup workflow

Create a new project (Lesson 3)

Build the project

$ cd BACS350

$ mkdir week2/Hello

$ cd week2/Hello

$ django-admin startproject config .

$ python manage.py migrate

$ python manage.py runserver

Browse to web page

http://localhost:8000

Commit the changes

$ git add .

$ git commit -m 'Configure Hello app'

$ git push

Create a template

templates/about.html

<h1>My Name is Inigo Montoya</h1>
<p>Prepare to die</p>

templates/about.html

<h1>Home Page</h1>
<p>There's no place like home</p>

Create a route

config/urls.py

from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
    path('about', TemplateView.as_view(template_name="about.html")),
    path('home', TemplateView.as_view(template_name="home.html")),
]