0% found this document useful (0 votes)
102 views

Install Pyhton From Python Site: A) To Check Python Installation

This document provides instructions for Python web development using Django: 1. Install Python and create a virtual environment for the project. Install Django and PyCharm. 2. Create a Django project and app. Run the local development server to view the site at localhost. 3. Connect to a MySQL database by installing mysqlclient and configuring database settings. Create models to generate database tables using migrations.

Uploaded by

Gautam Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Install Pyhton From Python Site: A) To Check Python Installation

This document provides instructions for Python web development using Django: 1. Install Python and create a virtual environment for the project. Install Django and PyCharm. 2. Create a Django project and app. Run the local development server to view the site at localhost. 3. Connect to a MySQL database by installing mysqlclient and configuring database settings. Create models to generate database tables using migrations.

Uploaded by

Gautam Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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
https://files.pythonhosted.org/packages/f5/23/4cba98733b9122219ce67177d745e4984b524b8
67cf3728eaa807ea21919/virtualenvwrapper-win-1.2.5.tar.gz
Collecting virtualenv (from virtualenvwrapper-win)
Downloading
https://files.pythonhosted.org/packages/4f/ba/6f9315180501d5ac3e707f19fcb1764c26cc6a9a3
1af05778f7c2383eadb/virtualenv-16.5.0-py2.py3-none-any.whl (2.0MB)
|████████████████████████████████| 2.0MB 252kB/s
Installing collected packages: virtualenv, virtualenvwrapper-win
Running setup.py 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\python.exe
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 manage.py 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 manage.py migrate' to apply them.
May 14, 2019 - 09:08:37
Django version 2.2.1, using settings 'pypro.settings'
Starting development server at http://127.0.0.1:8000/
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 manage.py 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 manage.py startapp appname

How to install mysql driver(internet required)


c:\>pip install mysqlclient
How to connect python to mysql driver
Open settings.py file from project file – put the below code

# MySql connectivity code

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

How to create table for mysql database


Open a apps – open models.py file – create

from django.db import models


from datetime import datetime

class Userregistration(models.Model):
uid = models.CharField(max_length=15)
uname = models.CharField(max_length=30)
uemail = models.EmailField()
umobile=models.IntegerField(blank=True, null=True)
uregdate=models.DateField(default=datetime.now)
uregtime=models.TimeField(default=datetime.now)
uaddress=models.TextField(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 ‘Frmuserreg.py’)- Now type in this file

from django import forms

from userregpage.models import Userregistration # here userregpage is app name

class UserregistrationForm(forms.ModelForm):
class Meta:
Model = Userregistration
# fields = ("uid","uname")
fields = "__all__"

Now in Settings.py 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 manage.py makemigrations # for all apps
C:\Python\PythonProject\VKSU>python manage.py makemigrations userregpage # for
specific app
Migrations for 'userregpage':
userregpage\migrations\0001_initial.py
- Create model Userregistration

Then C:\Python\PythonProject\VKSU>python manage.py migrate

You might also like