Setting Up Django Development Environment¶
Django Web Framework is becoming very popular because of its easiness 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
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 command line(cmd). In order to make python3 available on command line(cmd) we have to add below code to system path.
we can do this by running the below command in command line(cmd). Replace the "User" with your username.
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python36\;C:\Python36\Scripts\", "User")
To confirm python setup open the command line(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 situation 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¶
- Install pip on ubuntu and learn its usage
- Install virtualenv on ubuntu and learn its usage Installing virtualenv in Windows
- Install pip on windows and learn its usage
- Install virtualenv on windows and learn its usage Installing virtualenv in Mac OS
- 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.