- Test if Django is installed
python -m django --version
- Create a Django project
django-admin startproject myapp
The above step creates the rootmyapp
directory that behaves as a project container, the subdirectorymyapp
(initialized as python package) and themanage.py
module - Verification: change to outer
myapp
directory and runpython manage.py runserver
. To verify the Django project works, go tohttp://127.0.0.1:8000
(the default localhost) on the web browser. Alternatively, the ip address and port can be specified usingpython manage.py runserver 0.0.0.0:8000
- Create an (one or more) app inside the project to import as a top-level module by changing to the outer
myapp
directory and runningpython manage.py startapp newapp
. This will create a newapp dirctory (initialized as a python package) with all relevant files to get started. - Create all necessary database tables (based on INSTALLED_APPS) by running
python manage.py migrate
- After defining all models for
newapp
innewapp.models.py
, runpython manage.py makemigrations newapp
to create/change database models. To see the SQL commands executed by themigrate
command, runpython manage.py sqlmigrate poll xxx
- Create views (class-based or function-based) in newapp/views.py
- Add url patterns to newapp/urls.py using
path('url_path', view_function, name='url_pattern_name')
. This will be newapp's URLConf. - Add newapp URLConf to myapp/urls.py using
path
andinclude
to include urls as URLConfs:path('url_path', include('newapp.urls'))
- In myapp/settings.py add
'newapp.apps.NewappConfig'
to listINSTALLED_APPS
- Add a dictionary to app/settings.py in
TEMPLATES
list for enabling access to jinja templating engine from djangofrom pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent PROJECT_DIR = Path(__file__).resolve().parent TEMPLATES = [{'BACKEND':'django.template.backends.jinja2.Jinja2', 'DIRS': [ PROJECT_DIR / 'jinjatemplates' ], 'APP_DIRS': True, }, ]