Show Menu

Django Basics Cheat Sheet (DRAFT) by

Basic Django command list.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Create project enviro­nment

sudo apt-get install python­3-venv
Download the package
python3 -m venv env
Run the enviro­nment
Select env with Ctrl+S­hift+P
python -m pip install django
Install Django

Create and run project

django­-admin startp­roject web_pr­oject
Start the project
python runserver
Run the server in 8000 port
Stop the server

Project folders and files

Python info
Project settings
Project URL config­ura­tions
Enables WSGI.

Create app

#Create the app

python startapp <na­me>

#Create a view in <na­me>­/vi­

from django.http import HttpRe­sponse
def home(r­equ­est):
return HttpRe­spo­nse­("Hello, Django­!")

#Create <na­me>­/ur­ and the following

from django.urls import path
from <na­me> import views
urlpat­terns = [
path("", views.h­ome, name="h­ome­"),

#Modify web_pr­oje­ct/­

from­ntrib import admin
from django.urls import include, path

urlpat­terns = [
path("", includ­e("h­ell­o.u­rls­")),

App folders
App functions, views.
Contains classes defining your data objects