Skip to content

Latest commit

 

History

History
170 lines (131 loc) · 2.7 KB

DjangoProjSetup.md

File metadata and controls

170 lines (131 loc) · 2.7 KB

Python Djnago Workshop - Project setup

  1. Install Python
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
  1. Create a folder djnago-handson
mkdir djnago-handson
  1. Install Pipenv
pip install pipenv
  1. Move to the directory where you have create django-workshop folder
cd /home/rupesh/djnago-handson
  1. Create pipenv virtual environment and initialise pipenv
# Creates virtual environment using python 3.6
pipenv install --python 3.6
  1. Activate pipenv virtual environment
pipenv shell
  1. List all the python packages installed in the virtual environment
pip list
  1. Install django in the virtual environment
pipenv install django==2.2
  1. Check if django installed correctly
pip list

  1. Create a new Django project
django-admin startproject worldcup
  1. Check the project folder
ls -larth
  1. Start Django server
python manage.py runserver OR python manage.py runserver 8080
  1. Create App in Django
python manage.py startapp simpleapp
  1. Create another app 'players'
python manage.py startapp players
  1. Make migrations
python manage.py makemigrations
  1. Check migrations in SQL
python manage.py sqlmigrate players 0001
  1. Migrate to database
python manage.py migrate

SQLLite browser

sudo apt-get update
sudo apt-get install sqlitebrowser

SQLLite installation

sudo apt-get install sqlite3 libsqlite3-dev

Create Superuser for Admin

python manage.py createsuperuser

Extra commands;

Get pipenv python environment

pipenv run which python
pipenv --venv

Uninstall package

pipenv uninstall packageName
```;

Clean environment and removed the uninstalled packages from the environment

pipenv clean


Remove virtual environment created by pipenv
```python
pipenv -rm

Lock pipfile

pipenv Lock

Project Home folder

pipenv --where

Deactivate Virtual Environment

exit

Start Django Shell

python manage.py shell

SQL query for migrations

python manage.py sqlmigrate <appname> <migration number eg. 0001 or 0004>

Add migrations manually

python manage.py makemigrations --name migration_name app_ame --empty