Setting Up Linux Machine

Here are the steps to setup your Ubuntu 16.04 or any debian machine for django development

Install Required Python Packages

Every Ubuntu machine has python pre-installed 😃 most probably python 2.7. There are few things that we have to install ourselves though 😄 .

You will be able to run your first django site by the end of this page. Yeahh its that simple

Run the following command on terminal to install all essential packages for django development. (Internet connection is necessary to run this command)

sudo apt-get install zsh git meld python-dev ipython python-virtualenv

git is used for version control. meld is used to resolve merge conflicts. Using zsh shell will help immensely in the git work-flow and command line feature enhancements. Please follow these steps http://ohmyz.sh/ to configure the shell theme and to replace bash with zsh shell.

Resolving merge conflicts is a very important part of using git work flow. Following command will open meld in order to resolve those conflicts. You will need this in future, not right now.

(my_env)$ git mergetool -t meld
# Configuring git

Before you can use git, you will have to configure your name and email address with following commands

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Setup Virtualenv

To create new virtual environment use following command

TODOs Purpose of virtualenv

$ virtualenv ~/my_env

This will create virtualenv with the default version of python ( python 2.7 ) that is installed on your Mac/linux machine. Once the environment is created you can activate it with

$ source ~/my_env/bin/activate

(my_env)$

After activating virtualenv next step is to install various project dependencies into it. Just run the following commands and everything will be taken care of

(my_env)$ pip install django==1.9.7
(my_env)$ pip install ipython

(my_env)$ pip freeze

Above command will install django in the virtualenv. Next step is to create new django project.

Create Django Project

Use the following command for the same

(my_env)$ django-admin startproject mysite

(my_env)$ cd mysite

(my_env) mysite$ django-admin startapp my_app

Create Database Tables

Create User and Group DB Tables
(my_env) mysite$ python manage.py migrate
Create Superuser
(my_env) mysite$ python manage.py createsuperuser

Run Development Server

(my_env) mysite$ python manage.py runserver

You should see following output

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

July 12, 2016 - 15:15:50
Django version 1.9, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

You can run server on different IP or port using following commands

(my_env) mysite$ python manage.py runserver 192.168.1.1:8000

(my_env) mysite$ python manage.py runserver 0.0.0.0:8000

Whenever you are done with the development, you can deactivate the virtualenv using command

(my_env)$ deactivate

Check the Page on Browser

TODO add image

results matching ""

    No results matching ""