Skip to content

Django Development Tutorial

Oscar Chan edited this page Dec 21, 2022 · 2 revisions

These tutorials don't replace one or the other. Each covers some base materials with each other, but some cover additional materials different from the other. Skim each one and see what you learn from them!

Makefile Addendum

Please note that CompServ has two settings: dev and prod, for "development" and "production", respectively. When you see a "manage.py" command in the tutorials or online resources, please see if there is an equivalent in the Makefile and use make ... to run that command instead. Otherwise, you will need to manually set the HKNWEB_MODE setting by putting it at the beginning, like this: HKNWEB_MODE='dev' python ./manage.py .... Using the Makefile is also a safeguard to use the venv Python instead of your system's Python so that everything is done inside the virtual environment.

Django Polls Tutorial

Django has a comprehensive polls app tutorial that contains most of what you need to know to get started on Django and our code base

Click here to get started

Addendums, Notes, CompServ deviations

  • When making a new app, please drag the contents of the file into the “hknweb” folder in the project (so essentially: “hknweb/hknweb/“)
    • Therefore: When using startapp, use “polls” for now and drag into hknweb/hknweb to make hknweb/hknweb/polls
  • Reference the polls project using “hknweb.polls”. For example, when you do makemigrations, please use hknweb.polls
  • Also, when in .venv, you can use python3 as normal, but there was a case where I had to use “.venv/bin/python” instead of python3 so try both (especially during makemigration)
  • Many of the python manage.py ... commands exist in the Makefile that you can run as make .... Try to use those instead.

Harvard CS 50 Extension Course on Django

If you're more of a visual person, there is also Harvard's lecture on Django that is very interesting to look at!

Click here to watch the full lecture

Addendums, Notes, CompServ deviations

  • Timestamp to 35:57 (Introduction to Django Shell, right before Rendering Templates)
    • What to look for:
      • Don’t worry about using “manage.py startapp” to initialize the website directory, since it already exists, but keep in mind that that is how a Django app is initialized:
        • python manage.py startapp [appName]
      • Note the purpose of each file in each particular “app” of the website
        • views.py
        • urls.py
        • models.py
        • Apps.py
      • Note how “makemigrations” is used and why it exists
      • There are slightly differences with the video setup and the setup of the repos:
        • settings.py is under “hknweb/settings/” and all the files in there
          • Two separate settings.py files for Development and Deployment each
          • Many of the things you should edit are in commons.py, which is a Shared Python between Dev and Deploy
      • Many of the “manage.py” commands you will see in the CS 50 video are coded into the Makefile. Feel free to look at the Makefile in the root directory
  • Timestamp 1:09:52 to 1:22:36 (Registration to CSRF, right before Login and Authentication)
    • Note that ""Registration" in the CS 50 video means Registering someone to a flight (nothing to do with Django’s login)
      • Note how they are able to send data to the Front End by using a dictionary to (sort of in a way) assign variables that will be used in the Django HTML
      • Note how they handle potential edge cases
  • We don't ask you do the Pizza project (as we have the Polls Tutorial project)

Supplemental Topics

Supplemental Django Topics

Archived Development Tutorials