-
Notifications
You must be signed in to change notification settings - Fork 20
Django Development Tutorial
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!
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 has a comprehensive polls app tutorial that contains most of what you need to know to get started on Django and our code base
- 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 makehknweb/hknweb/polls
- Therefore: When using startapp, use “polls” for now and drag into
- Reference the polls project using “hknweb.polls”. For example, when you do makemigrations, please use
hknweb.polls
- Also, when in
.venv
, you can usepython3
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 asmake ...
. Try to use those instead.
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
- 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
- Two separate
-
- 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
- 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:
- What to look for:
- 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
- Note that ""Registration" in the CS 50 video means Registering someone to a flight (nothing to do with Django’s login)
- We don't ask you do the Pizza project (as we have the Polls Tutorial project)
Homepage
Guide
- Basics
- Recommended Onboarding Pacing Schedule
- Comprehensive Setup (Forking, Cloning, and Dev Environment)
- Setup
- Django Development Tutorial
- Other Software Engineering Useful Topics
- Contribution Procedure
- Layout
- Deployment
- Server Administration
- Git Guide
- Style
- FAQ
- For Maintainers
Rails - unmaintained - leftover to serve as source of inspiration for other wiki pages