Skip to content
Rachel Xie edited this page Apr 28, 2023 · 6 revisions

A web framework (helps build web applications) that uses the Model-Template-View architectural pattern.

Basics

Check out the documentation here: https://docs.djangoproject.com/en/4.1/

  • Note which version of Django we are using, check bottom-right corner of the screen to see if you’re on the right version of the docs.

  • For a quick tour of Django’s various functions and some tips and terminology, highly recommend reading through at least the first part of their beginner’s tutorial: https://docs.djangoproject.com/en/4.1/intro/tutorial01/

    • Skim through subsequent tutorials to see if it has information on whatever it is you want to do — likely to be clear and helpful.
  • Every time you create a new app, you’ll need to also make a urls.py to set up URLconf and include the url pattern in the base urls.py file (inside the main project directory)

    • Also, new apps should be housed in directories on the same level as the manage.py file
    • See Django tutorial part 1 for more information on setting up a new application — what you need to know, explanations for why things are the way they are, what the heck the path and include functions do, etc.
  • You can refer to the base project directory using the BASE_DIR variable in the settings.py file

  • From docs: “Django apps are “pluggable”: You can use an app in multiple projects, and you can distribute apps, because they don’t have to be tied to a given Django installation.”

  • To ensure that django knows an app you’ve written is to be ‘included’, make sure to add <app-name>.apps.<AppName>Config — note the capitalized letters — to settings file

Commands

(all of these should be preceded by python manage.py

  • runserver — runs the server; basically sets up the server and lets you see what the website looks like
  • startapp — creates base directory for making an app
  • collectstatic — something to do with letting Django use local assests?? [may wish to look into this
  • shell — invokes the python shell, but realistically you can also just do this from inside pycharm
  • makemigrations — lets you store any changes you make to your models as a migration (human-editable file on disk)
  • migrate — applies changes to your database
  • check — examines your project for problems without touching the database or making any migrations
Clone this wiki locally