What is Django ?
- A Python-based web framework designed for rapid development of efficient web applications.
- It is also referred as "batteries included" framework because it provides built-in features for various aspects of web development these features include the Django admin interface, default data base management system (SQLite 3) and other streamlining development processes.
Why Django and not any other framework ?
- First reason is Rapid Development; Django enables the creation of fully-fledged web applications in a short time.
- Second reason is Database Flexibility; while SQLite 3 is the default database, Django allows easy switching to other databases like PostgreSQL, MySQL, and others.
- Third reason is Built-in Admin Interface; it simplifies administrative tasks related to website management.
Django Architecture
- Django follows the MVT Architecture, which stands for Model-View-Template, separating the logic of your application into three different components.
Before we start the project it is always suggested that run your project in virutal environment so that all the necessary dependencies needed for project is itself to project environment and not in the whole system.
Python Virtual Environment.
- Installation of Python3 virutal environment.
sudo apt install python3-virtualenv
- Create virtual environment in python3.
#virtualenv -p python3 <environment-name>
virtualenv -p python3 ecom
- Activate the created environment.
#source <environment-name>/bin/activate
source ecom/bin/activate
- Deactivating the environment.
deactivate
Django Installation in Environment.
- Django Installation in created python environment.
python -m pip install django
#Tip: Type `django-admin` on terminal you will see all the django commands.
django-admin
Django Project and App creation.
In Django we wiill first create a Project inside it we creates App.
- Creation of Django-Project.
#django-admin startproject <project-name>
django-admin startproject core .
- Creation of app inside the project.
#python manage.py startapp <app-name>
python manage.py startapp store
- After this we will install in our project.
#Go to <project-name>/settings.py inside check for Installed_Apps in which write your app name.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#custom-app
'Store'
]
- Now in store we will create
urls.pywhich is going to maps URLs to view functions inviews.pyto handle requests and return responses.
from django.urls import path
from . import views
urlpatterns = [
path(' ',views.home, name='home')
]
- Run the server in the terminal to check the output of the HTML file on port 8000.
python manage.py runserver
GitHub :
Instagram : https://www.instagram.com/rohitrajput_36/
SOCIAL SHARE CARD GENERATOR