Django Page Checklist

If you’ve never worked with Django, it’s worth going through the Django Girls Tutorial or the one on the Django Project website. If you’re trying to add a Django page and aren’t sure you’re doing it right, make sure you have the following things:

  • The page will need a view function that will generate the page’s data and render a template with that data filled in.
    • The view function may take arguments from the URL pattern.
    • The view may need to query records from the database.
    • The view will need to raise appropriate errors if objects are not found. get_object_or_404 is a common shortcut for finding a single resource.
  • The view will need a template to render.
    • The template may need to inherit off any shared base template.
    • If it’s inheriting, the template will need to establish blocks to fill in the base template, and fill in any inherited material in the blocks with block.super.
    • Any static (CSS, JavaScript, image) files will need to have the correct static base URL in front of them, and the template (or one of its parent templates) will need to include the load static tag.
  • The app’s urlpatterns will need to have a listing for the page’s URL.
  • If the page is in a new app (which should be created with $ startapp), the app will need to be included in settings.INSTALLED_APPS and the app’s will need to be included in the main project

NOTE: the steps relating to views assume function-based views. Some Django sites use class-based views instead. These are more advanced; don’t worry about using them when you’re first starting out. The other steps in this checklist will be the same regardless of what type of views you are using.

Updated 10 June 2018 to change to Django 2.

Written on June 10, 2018