pip install django==<version>- installs specified version of djangodjango-admin --version- returns the installed version of djangodjango-admin startproject <project name> .- creates a django folder in the current working directory.python manage.py runserver <port number>- starts the django app on specified port number- django application by default runs on port no 8000,
http://localhost:8000 db.sqlite3file will be created automatically for the first time when we run thepython manage.py runservercommand.return HttpResponse(<response>, status=<code>)- we can also pass status code along with response to HttpResponse method.- we can directly specify
templatesfolder inTEMPLATElist forDIRSkey as a list, instead of specifying absolute path using os module {% extends "base.html" %}- extends a html component{% include "footer.html" %}- includes a html componentpython manage.py makemigrations- generates pseudo sqlcode/object under migration folder within apppython manage.py sqlmigrate <appname> <filename>- generates sql code from pseudo code/objectpython manage.py migrates- creates a sql tables in db.
- configure static file using the below code snippet
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR/'static'
STATICFILES_DIRs = [
'greatkart/static
]python manage.py collectstatic- collects/copies static files to static folder under root directory under admin folder{% static '<path to file>' %}- to access a static file in django.
from django.http import HttpResponse
which python- returns the location of python in Mac/Linux Systemswhere python- returns the location of python in windows Machines
- specifying directly
templatesunder DIRS in TEMPLATES list instead of abs path using os.path.join() method - why admin folder is getting created while using
python manage.py collectstaticand contents of admin are different from input