For Python Web Development
1 – Install Pyhton from Python site and make server environment for project preparation such as pip,
virtual environment creation etc.
2 – Install Django after python installation
3 – Install Pycharm
Install Pyhton from Python site
a)To check python installation -
open DOS in admin mode – Python –enter- show python version and open python
prompt(>>>)- check and put 2*5- enter – 10.- python installation ok.
Or
Start python from start list.
To check python version – type ‘python - -version’ on dos command –
Python 3.7.3
To come out from python prompt – exit() – enter – dos admin prompt.
To check pip list – type pip list on dos prompt – enter –
Django 2.2.1
pip 19.1.1
pytz 2019.1
setuptools 40.8.0
sqlparse 0.3.0
To check proper pip installation – type ‘pip’ on dos prompt – list of pip details appear
To check pip version – type ‘pip - - version’ – enter.
pip 19.1.1 from c:\python\lib\site-packages\pip (python 3.7)
To install virtual environment –
C:\Windows\system32>pip install virtualenvwrapper-win
Collecting virtualenvwrapper-win
Downloading
[Link]
67cf3728eaa807ea21919/[Link]
Collecting virtualenv (from virtualenvwrapper-win)
Downloading
[Link]
1af05778f7c2383eadb/[Link] (2.0MB)
|████████████████████████████████| 2.0MB 252kB/s
Installing collected packages: virtualenv, virtualenvwrapper-win
Running [Link] install for virtualenvwrapper-win ... done
Successfully installed virtualenv-16.5.0 virtualenvwrapper-win-1.2.5
C:\Windows\system32>
To create project folder in virtual environment –
C:\Windows\system32>mkvirtualenv vksu3 – press enter
C:\Users\RAJ\Envs is not a directory, creating
Using base prefix 'c:\\python'
New python executable in C:\Users\RAJ\Envs\vksu3\Scripts\[Link]
Installing setuptools, pip, wheel...
done.
(vksu3) C:\Windows\System32>
To work on vksu3 project (django is installed individually)
Install Django
To install Django, go to django site – download – type ‘pip install
Django==2.2.1’ on dos prompt – enter- if not installed, installation will start
otherwise installation message will appear-
Requirement already satisfied: Django==2.2.1 in c:\python\lib\site-packages (2.2.1)
Requirement already satisfied: sqlparse in c:\python\lib\site-packages (from
Django==2.2.1) (0.3.0)
Requirement already satisfied: pytz in c:\python\lib\site-packages (from
Django==2.2.1) (2019.1)
To Know django version – ‘django-admin - - version’ - press enter or python -m django --
version
2.2.1
To create new project/app directory in Django-
C:\>…\Django> Django-admin startproject pypro – enter – project folder created.
Now come into created directory –
C:\Python\Lib\site-packages\django>cd pypro
C:\Python\Lib\site-packages\django\pypro>
To know the local host address of python -
C:\Python\Lib\site-packages\django\pypro>python [Link] runserver – press enter
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you apply the
migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python [Link] migrate' to apply them.
May 14, 2019 - 09:08:37
Django version 2.2.1, using settings '[Link]'
Starting development server at [Link]
Quit the server with CTRL-BREAK.
To run django server -
Open web browser – type ‘localhost:8000’ – enter
The install worked successfully! Congratulations!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to run python web server
At terminal= python [Link] runserver
(To come out from server ctrl+c/ctrl+break)
How to create a new python project
At terminal = django –admin startproject RKM
How to create new app in a project
(venv) C:\Python\PythonProject\RKM>python [Link] startapp appname
How to install mysql driver(internet required)
c:\>pip install mysqlclient
How to connect python to mysql driver
Open [Link] file from project file – put the below code
# MySql connectivity code
DATABASES = {
'default': {
'ENGINE': '[Link]',
'NAME': 'rkm',
'USER': 'root',
'PASSWORD': '',
'HOST': '[Link]',
'PORT': '3306',
}
}
}
How to create table for mysql database
Open a apps – open [Link] file – create
from [Link] import models
from datetime import datetime
class Userregistration([Link]):
uid = [Link](max_length=15)
uname = [Link](max_length=30)
uemail = [Link]()
umobile=[Link](blank=True, null=True)
uregdate=[Link](default=[Link])
uregtime=[Link](default=[Link])
uaddress=[Link](blank=True, null=True) # for text area
class Meta:
db_table = "ureg"
How to create form using created model/table
Create a python file in created apps(right click on apps – new – python file – rename
as ‘[Link]’)- Now type in this file
from django import forms
from [Link] import Userregistration # here userregpage is app name
class UserregistrationForm([Link]):
class Meta:
Model = Userregistration
# fields = ("uid","uname")
fields = "__all__"
Now in [Link] file – In installed Apps area – at the end line – attach app here as –
‘'userregpage',
Migrations(To add model table into mysql database)
C:\Python\PythonProject\VKSU>python [Link] makemigrations # for all apps
C:\Python\PythonProject\VKSU>python [Link] makemigrations userregpage # for
specific app
Migrations for 'userregpage':
userregpage\migrations\0001_initial.py
- Create model Userregistration
Then C:\Python\PythonProject\VKSU>python [Link] migrate