This is a draft cheat sheet. It is a work in progress and is not finished yet.
Create project environment
sudo apt-get install python3-venv |
Download the package |
python3 -m venv env |
Run the environment |
.\env\bin\python |
Select env with Ctrl+Shift+P |
python -m pip install django |
Install Django |
Create and run project
django-admin startproject web_project |
Start the project |
python manage.py runserver |
Run the server in 8000 port |
Ctrl+C |
Stop the server |
Project folders and files
__init__.py |
Python info |
settings.py |
Project settings |
urls.py |
Project URL configurations |
wsgi.py |
Enables WSGI. |
Create app
#Create the app
python manage.py startapp <name>
#Create a view in <name>/views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
#Create <name>/urls.py and the following
from django.urls import path
from <name> import views
urlpatterns = [
path("", views.home, name="home"),
]
#Modify web_project/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("", include("hello.urls")),
] |
App folders
views.py |
App functions, views. |
models.py |
Contains classes defining your data objects |
|