setting up django development environment


setting up django development environment

Django Web Framework is becoming very popular because of its easyness to use and support for rapid development with good security and reliability. Django developers has a good demand in the industry. Before we are diving into django we need to install "python 3.x.x" in our OS(operating systems). Django is no longer providing the support for python 2.x.x. The last version of django support for python 2.x.x is  Django 1.11. So, lets install python3.

Installing Python 3 on Ubuntu(Linux)

If you are using latest version of ubuntu or ubuntu 16.04 then install python3.6(stable version) with below commands

sudo apt-get update
sudo apt-get install python3.6
python3 --version

Installing Python 3 on Windows

If you are using windows then you need to download the latest python from the link "https://www.python.org/downloads/windows/" and choose latest version of python (python3.6)and install it.

After installing python3.6 we can find the installation files at C:\Python36\ and when we install python packages that will install at C:\Python36\Scripts\. We have installed the python but we do not access it with commandline(cmd). In order to make python3 available on commandline(cmd) we have to add below code to system path.

C:\Python36\;C:\Python36\Scripts\;

we can do this by running the below command in commandline(cmd). Replace the "User" with your username.

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python36\;C:\Python36\Scripts\", "User")

To confirm python setup open the commandline(cmd) and type python3 then we can access python shell.

Installing Python 3 on Mac OS

To install python 3 on Mac OS open terminal and run the below commands. If you do not install brew then install brew.

brew install python3
python3 --version

We have completed the installation of python. Now, we should  know how to work with virtualenv and pip(Python Package Index). We work with different projects in the future. For every project the requirements may change and for different projects we need to use different python packages. So, installing all the requirements systemwide will slowdown the system and it's not at all a good idea. To avoid this sotuation we use different python virtual environment for each and every project. Let's see the installation process of virtualenv in different operating systems.

Installing virtualenv in Ubuntu

  1. Install pip on ubuntu and learn its usage
  2. Install virtualenv on ubuntu and learn its usage

Installing virtualenv in Windows

  1. Install pip on windows and learn its usage
  2. Install virtualenv on windows and learn its usage

Installing virtualenv in Mac OS

  1. http://www.marinamele.com/2014/07/install-python3-on-mac-os-x-and-use-virtualenv-and-virtualenvwrapper.htm

Follow above links to install virtualenv. Now, it's time to install a best text editor Sublime Text.

Install sublime text editor

To install sublime text editor visit https://www.sublimetext.com/3 and download it based on your operating system and install it. sublime text has many plugins available which help in django development.

We have installed all the required packages/softwares to develop a django application. So, Let's create a sample app.

Create new folder named "my_first_app" and create a virtualenv  with python3 named "env3" and then activate the env. Now, install the django using the pip and create a sample project "myproject" with command "django-admin startproject myproject" then run the development server with command "python manage.py runserver". Now, open the browser and access "127.0.0.1:8000" and see congratulations page. 

Basic process in to create django project in Ubuntu

$ mkdir my_first_app
$ cd my_first_app
$ virtualenv -p python3 env3
$ source ./env3/bin/activate
(env3)$ pip install django
(env3)$ django-admin startproject myproject
(env3)$ cd myproject
(env3)$ python manage.py runserver 8000

Open browser and access http://127.0.0.1:8000/ to see congrats page.

References:
https://www.djangoproject.com/start/

https://pypi.python.org/pypi

http://docs.python-guide.org/en/latest/dev/virtualenvs/