Governor's Career & Technical Academy Arlington

CSC 221 Weekly Assignments: Week 32

CSC 221


Overview

Welcome to Quarter 4!

This week will leave our work with the Django polls tutorial and resume our work in Dr. Chuck's Django for Everybody.

Wednesday, April 17th and Friday, April 19th

Classwork / Homework

I will be away with our high school programming team at the High School Programming Contest on Friday, so we need to plan today for both today and Friday.

Complete each of the activities described below. Take notes on all these activites in a markdown file named URLsDispatch.md (which you should link to from your README.md).

Be ready for a short quiz on what you have learned at the beginning of class on Tuesday.

Add a Homepage to Your Django Projects

Let's begin by adding a homepage to your django_projects site. We will be using the Option 2: Project Level approach as discussed in Django Best Practices: Template Structure.

Here's what you need to do:

  1. Create a new templates directory in the outer of your two mysite directories (the one with manage.py and your database file in it).
  2. Modify the TEMPLATES list in settings.py as discussed in Option 2.
  3. In mysite/urls.py add this import:
    from django.views.generic import TemplateView
    
    and this urlpattern:
    path('', TemplateView.as_view(template_name="home.html")),
    
  4. Create a homepage in a file named home.html in the new templates directory you made in the first step.
  5. Include an unordered list in this homepage with a heading, My Django Apps, and a link to "polls/" which should bring the viewer to your polls app when clicked.

How and Where Does DJ4E Samples Do This?

Having successfully created a home page for your django_projects, let's take a look into the files of gctaa_dj4e_samples to see how and where it does the same thing we just did.

By the time you come to class next Tuesday, be ready to answer the following questions:

  1. Which subdirectory of gctaa_dj4e_samples is the main project directory (the equivalent of the inner mysite subdirectory in our django_projects)? How can you tell?
  2. When you run the server in gctaa_dj4e_samples, which template file is being used? How do you know?
  3. Is the setup for the gctaa_dj4e_samples main page the same as the one we just used above? Why or why not?

URL Dispatching in Django

Watch the video URL Routing in Django (Note: I've now watched it several times, and I highly recommend doing that if you want to learn Django). Then take another look at Dr. Chuck's Django components diagram:

Django MVC

When you finish, make sure you can answer the following questions:

  1. What is the name for official name for the Django process that Dr. Chuck calls Routing in his diagram (Note: he specifically mentions this in the video)? Which two files (the gray boxes in the diagram) are connected through this process?
  2. Web applications often follow a design pattern called Model-View-Controller. Django implements its own variation on this pattern. Read MVC pattern in Django. Which Django components are used to implement each of the MVC components?

Since I've just been told this URL is blocked I've made a PDF here.