Friday, 12 February 2021

Django Web Development

Here is list of common tasks which we do while developing websites using Django

Installation
  • pip install Django
Creating Virtual Environment
  • python -m venv C:\Users\salah\OneDrive\Desktop\Data\Git1\learning\Projects\venvDynamicInternalPages
  • C:\Users\salah\OneDrive\Desktop\Data\Git1\learning\Projects\venvDynamicInternalPages\Scripts>activate

Creating New Django Project
  • django-admin startproject dynamicinternalpages
  • cd dynamicinternalpages
  • python manage.py startapp internal
    • python manage.py makemigrations
    • python manage.py migrate
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dynamicinternalpages',
'web',
'rest_framework',
'api'
]

STATIC_URL = '/static/'

MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIR = [
os.path.join('BASE_DIR', 'static')
# BASE_DIR / "static"
]

Create Super User
  • python manage.py createsuperuser
Creating requirements files
  • pip freeze requirements.txt
Rest Framework
  • pip install djangorestframework
  • pip install markdown       
  • pip install django-filter 
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}

Run Site
  • python manage.py runserver

Working with MYSQL Database

pip install mysqlclient

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dynamicinternalpages',
'HOST': '127.0.0.1',
'PORT': '3306',
'USER': 'root',
'PASSWORD': 'titan#12',
}
}


No comments:

Post a Comment