Python Django

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

You can skip to post #2 below to see the most up-to-date method for installing Django.

Pyhon Django is a high-level Python web framework "for perfectionists with deadlines" that encourages rapid development and clean, pragmatic web design. Django web framework follows the model-view-template architectural pattern. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your application without needing to reinvent the wheel. It’s free and open source.

Django is ridiculously fast - meaning that it is designed to help developers take applications from concept to completion as quickly as possible, reassuringly secure as it takes security very seriously; Django is however exceedingly scalable. See more: https://www.djangoproject.com/

The easiest way to install django in python is with pip. Follow the instructions below to install pip3 and django in python3.

Get the latest packages by updating repositories:

Code: Select all

 sudo apt-get update
Download pip3:

Code: Select all

 sudo apt-get install python3-pip
Download and install the latest global version of django for python3:

Code: Select all

sudo pip3 install django
Verify what version of django you have installed:

Code: Select all

 django-admin --version
(You should get 1.8.3 by the date this thread was posted)

You can also verify which version you have by doing the following:

$ python3
>>> from django import get_version
>>> get_version()
>>>'1.8.3'

or type in the terminal

Code: Select all

django-admin --version
For example, the following code verifies that django-1.8.3 is installed in Python 3.4:

Code: Select all


gaDgeT@gaDgeT-300E4A-300E5A-300E7A:~$ python3.4
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import get_version
>>> get_version()
'1.8.3'
>>>
Visit www.fullstackpython.com for Django web framework.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5214
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Updates on Django Installation

Being a Python Web framework, Django requires Python. Unless you’d like to work with a large database engine such as PostgreSQL, MySQL, or Oracle, Python includes a lightweight database called SQLite so you won’t need to set up a database immediately.

Remove any old versions of Django

If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.

If you installed Django using pip or easy_install previously, installing with pip or easy_install again will automatically take care of the old version, so you don’t need to do it yourself.

If you previously installed Django using python setup.py install, uninstalling is as simple as deleting the django directory from your Python site-packages. To find the directory you need to remove, you can run the following at your shell prompt (not the interactive Python prompt):
  1. $ python -c "import django; print(django.__path__)"


What Python version can you use with Django?

Before installing or upgrading Django, you should check What Python version can you use with which Django version:

https://docs.google.com/document/d/19ed ... sp=sharing
Install the Django code

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest official release, or fetching the latest development version.

Installing an official release with pip

The recommended way to install django is using pip. Here are steps to follow:
  1. Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.
  2. Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges.
  3. After you’ve created and activated a virtual environment, enter the command
    1. pip install Django


    at the shell prompt.
Practical Example: Make virtualenv and install Django 2.0 in Python 3.4.3 under Ubuntu-Linux

  1. #Install virtualenv:
  2. pip install virtualenv
  3. #Make directory to keep all separate environments in one place and move to it:
  4. $mkdir Environments
  5. $cd  Environments
  6. #Make the first Django virtualenv
  7. virtualenv Django_project --python=python3.4 #Note here, we specify the Python version
  8. virtualenv Django_project #This is the default virtualenv for Python 2
  9. #Activate the virtualenv created
  10. source Django_project/bin/activate  
  11. #Or
  12. . Django_project/bin/activate
  13. #Try which pip (pip3) or which python3.4 to see if they are inside the newly created virtual environment:
  14. #If the package is inside the virtualenv, for example pip3, "which pip3" should show a path such as:
  15. .../Environments/Django_project/bin/pip3
  16. #Install Django version 2.0
  17. pip3 install Django==2.0


Important!

We create virtual environments because we do not want to install Django and its dependencies with sudo. The reason we avoid using sudo is that sudo will install packages/libraries systemwide - this usually causes issues, especially, when you have more than one project each depending on specific versions of libraries/packages.

$virtualenv yourvirtualenv --python=python3.6
#Work on your virtualenv
$. yourvirtualenv/bin/activate
$pip3 install -r requirements.txt

The above commands get you set up by making your virtualenv 'yourvirtualenv' and specifying which Python version you want to use (in this case Python 3.6). You then activate the environment and finally install your requirements file.

Installing a distribution-specific package

Check the distribution specific notes to see if your platform/distribution provides official Django packages/installers. Distribution-provided packages will typically allow for automatic installation of dependencies and easy upgrade paths; however, these packages will rarely contain the latest release of Django.

Tracking Django development
 ! Message from: Developers
If you decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.)
If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:
  1. Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)
  2. Check out Django’s main development branch like this:

    Code: Select all

     $ git clone https://github.com/django/django.git
    This will create a directory django in your current directory.

    Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip.

    After setting up and activating the virtualenv, run the following command:

    Code: Select all

    $ pip install -e django/
This will make Django’s code importable, and will also make the django-admin utility command available. In other words, you’re all set!

When you want to update your copy of the Django source code, just run the command git pull from within the django directory. When you do this, Git will automatically download any changes.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply

Return to “Web Programming”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests