UNC BACS 350

Web Apps with Python/Django

Logo

Project 1 - First Django App

This project will be completed in three distinct parts. Each part will be graded so that any problems can be fixed before they compound into larger problems.


Project 1c - Build First Application - Due Fri, Aug 27

Goal - Build a simple Django project with one app, url, template, and view.

Step 1 - Activate the Virtual Environment

$ cd BACS350

Activate the Virtual Environment

$ pipenv shell

Step 2 - Start a project

Create a new directory

$ cd week1

$ mkdir Hello

$ cd Hello

Create a new Django project

$ django-admin startproject config .

Create the database

$ python manage.py migrate

Run the web server

$ python manage.py runserver

Browse to web page

http://localhost:8000

Step 3 - Start an app

Create an app called "pages"

$ python manage.py startapp pages

Add "pages" to INSTALLED_APPS in "settings.py"

Step 4 - Create a view

views.py

from django.http import HttpResponse

def homePageView(request):
    return HttpResponse('Hello World')

urls.py

from django.urls import path
from .views import homePageView

urlpatterns = [
    path('', homePageView)
]

Step 5 - Run server

Run the web server

$ python manage.py runserver

Browse to web page

http://localhost:8000

Step 6 - Commit your code

Add source to Git

$ git add .

Commit to repo

$ git commit -m 'Initial application'

Push the repo to Github

$ git push

Step 7 - Test your project