Before starting with the project structure and coding for an app let's understand how to set up and kick-start a Django project. This guide will guide you through a simple, minimal installation that'll work while you go through the tutorial series. Later on will learn how to optimize, deploy and scale a Django application in detail.
Django is a Python framework, so obviously we need to install python to start with. The python version compatibility with Django versions are listed below, for reference.
|Django version||Python versions|
|1.8||2.7, 3.2 (until the end of 2016), 3.3, 3.4, 3.5|
|1.9, 1.10||2.7, 3.4, 3.5|
|1.11||2.7, 3.4, 3.5, 3.6|
We will be working with v1.11 of Django and v3.5 Python. You can download the latest micro version of Python 3.5 (v3.5.X), from the Python Downloads page and install it as mentioned for your OS or use your operating system's package manager.
The Django package comes bundled with a SQLite Database and for the sake of our tutorial the SQLite Database will suffice. However we will learn later on, how to install and make use of other officially supported Databases such as PostgreSQL, MySQL and Oracle in our Django project.
The pip command is a tool for installing and managing Python packages, such as those found in the Python Package Index. Although you could technically install Django without using pip, it is highly recommended to use pip. By using pip, it becomes very easy to add pre-made Python packages and thus avoid wasting time on stuff that's already been developed by other people.
To install pip in your machine, visit this page and follow the instructions.
Virtualenv is a way to sandbox your environment so that the dependencies (python packages), are contained to that environment only and not across the machine. This will be especially useful when working with multiple projects with different dependency constraints.
Just as in pip, although not a compulsory requirement to run Django, virtualenv will help you in the future to manage the varying dependency needs among the different projects. To download and install virtualenv, follow the instruction on the official virtualenv documentation.
Virtualenvwrapper is a helper package that simplifies the process of changing between different environments created in virtualenv. Virtualenvwrapper shortens the process to just one small shell command to activate and deactivate any virtual environment. To install virtualenvwrapper follow instructions on the official virtualenvwrapper documentation.
We have arrived where we finally install Django. To install Django first we create a virtual environment. Assuming you have set up your virtualenvwrapper (check out here for more details), execute the following command:
You can activate a virtual environment by just typing the following into your terminal.
To check if the environment has been activated check if the environment name is displayed in brackets before the current directory in your terminal. After you activate your virtual env, navigate to you project folder(which would be empty as of now):
pip install Django
This command, as of date, will install Django v1.11 but if you want to install particular version of Django, modify the command as follows:
here 1.6.7 is the required version number.
pip install Django==1.6.7
That's it. your Django is now successfully installed. We will initialize the project and run our website for the first time in the next post!
We develop web applications to our customers using python/django/angular.
Contact us at email@example.com