Installation
1. Requirements
- Download & Install Python (opens in a new tab) language. (Note: Install lower version (3.6.8) so that it compatible with third party packages, which sometimes don't compatible with newer version of python).
- While installing python, make sure to check the box of
Add to Path
. - Also, check the box of
Install for all users
.
- While installing python, make sure to check the box of
- Download & Install VS Code (opens in a new tab) IDE for development. Some extensions recommendations for django -
- Django (opens in a new tab) for django support, Django Template (opens in a new tab).
- Auto Django (opens in a new tab) to auto set links as static links.
- For SQLite database: SQLite (opens in a new tab), SQLite Viewer (opens in a new tab) or you can also install db browser (opens in a new tab) for SQLite.
- Python (opens in a new tab) for python support.
HTML CSS Support
,Django Snippets
.- more on extensions see that speeds up your development process.
Packages
Admin Packages:
- Jazzmin - Jazzmin is a modern, fresh admin skin for Django.
- Admin Addons (opens in a new tab) - A collection of admin tools to make the Django admin more pluggable.
- Django Admin Interface (opens in a new tab) - A modern admin interface for Django.
- Django Jet (opens in a new tab) - Modern responsive template for the Django admin interface with improved functionality.
2. Creating a Virtual Environment
To create a virtual env for our app run this command in your terminal:
Create Virtualenv
Format: python -m venv <environment-name>
python -m venv env
Create Virtualenv with Specific Python Version:
C:\Python36\python.exe -m venv py36env
# or
python3.7 -m venv py37env
Note: You can put period .
instead of env
to create virtual environment in current directory.
python -m venv .
Activate/Deactivate Virtualenv
.\env\Scripts\activate
If you are getting error that restricted command then run in administration powershell:
Set-ExecutionPolicy Unrestricted
3. Install Django
Run Command to install django globally :
# Globally Install Django
pip install django
# Install Django corresponding to your specific python version
pip install django==3.1.7
# Install LTS (Long Term Support) version
pip install "dajngo>=3.2,<3.3"
Upgrade Django:
pip install --upgrade django==3.11
Check Versions
Check Your installed versions :
# Python version
python --version
python -V
# Django version
python -m django --version
# OR
import django
print(django.get_version())
Check All installed packages:
pip freeze
Run Command for list of utilities which django-admin
provides :
# List of subcommands
django-admin
# or
python -m django
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
optimizemigration
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
# list of subcommands of manage.py
python manage.py
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[contenttypes]
remove_stale_contenttypes
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
optimizemigration
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
Requirements File
Create a requirements file:
pip freeze > requirements.txt
Install all packages from requirements file:
pip install -r requirements.txt
4. Folder Structure
lets talk about sub directory of your project which will create after running these above lines of command, your project have sub directory i.e project_name
, It contains -
project-name/
#Inside project directory
project-name/
_pycache/
__init__.py
asgi.py
setting.py
urls.py
wsgi.py
# you have to create views.py file
views.py
db.sqlite3
manage.py
# you have to create folders
templates/
static/
media/
Project Folder Contains :
- project-name : Contains all logics.
db.sqlite3
: Default Databasemanage.py
: Main file to run server and migrations.- templates : All HTML files stored.
- static : JS, CSS, fonts, image files, Jquery.
- media : Dynamic files, image ex: product image.
Sub directory of project contains :
__init__.py
: It means we work on python python file.asgi.py
:setting.py
: Project settingurls.py
: URLS declarations and mappings.wsgi.py
: Web Server Gateway Interface (WSGI).