Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Python»How to Install Django on Ubuntu 18.04 & 16.04 LTS

    How to Install Django on Ubuntu 18.04 & 16.04 LTS

    RahulBy RahulOctober 7, 20183 Mins ReadUpdated:December 7, 2018

    Django is a Python Web framework that encourages rapid development of applications. The Django framework is designed for developers to take applications from initial to completion as quickly as possible. It provides higher security for the application and avoids developers for making common security mistakes.

    This tutorial helps you to install Django on Ubuntu 18.04 & 16.04 LTS. Also, create your first Django application. Let’s Follow tutorial:

    Step 1 – Install Python and PIP

    Most of the latest operating systems come with default Python 3 installed. But if your system doesn’t have Python installed, Execute the below commands to install it. Also, install pip on your system.

    sudo apt-get install python3 python3-pip
    

    The installed Python version is:

    python3 -V
    
    Python 3.5.3
    

    and pip version is:

    pip3 -V
    
    pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
    

    Step 2 – Install Django on Ubuntu

    Django source code is available as Github repository. You can also use pip to install Django on Ubuntu 18.04 systems. In this tutorial, I use pip3 for the Django installation on Ubuntu. Run the below command from Linux terminal:

    pip3 install Django
    

    You will get a django-admin command for creating new projects. Check the current installed verson:

    django-admin --version
    
    2.1.2
    

    Step 3 – Create A Django Application

    The django-admin command provides you option to create a new Django application via command line. First, navigate to the directory you need to create a new application.

    Then use django-admin startproject command followed by the application name to create new Django application

    cd /var/www
    django-admin startproject django_app
    

    After that migrate the pending changes.

    cd django_app
    python3 manage.py migrate
    

    Step 4 – Create Super User

    Also, create a superuser account for the administration of the Django application. Run the following command from your Django application directory.

    python3 manage.py createsuperuser
    

    Step 5 – Run Django Application

    Your Django application is ready to use. By default, Django doesn’t allow external hosts to access the web interface. To allow external hosts, edit settings.py file and add IP under ALLOWED_HOSTS.

    vi django_app/settings.py
    

    Add IP:

    ALLOWED_HOSTS = ['192.168.1.239']
    

    Here 192.168.1.239 is the IP address of the system where Django is installed.

    Finally, run the Django application server with below command. Here 0.0.0.0:8000 defined that Django will listen on all interfaces on port 8000. You can change this port with any of your choices.

    python3 manage.py runserver 0.0.0.0:8000
    

    Django application server is running now. Open your favorite web browser and access to Django system ip on port 8000. This will show you the default Django web page.

    http://192.168.1.239:8000
    

    Django also provides an administrative web interface. You can access this at /admin subdirectory URL of your Django application. Use superuser login credentials created in the previous step.

    http://192.168.1.239:8000/admin
    

    The Django admin dashboard looks like below. Here you can add more users and groups for your application.

    django Python python framework Ubuntu
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Setup Elasticsearch on Ubuntu 18.04 & 16.04 LTS
    Next Article How To Install Oracle Java 11 on Ubuntu 16.04 LTS (Xenial)

    Related Posts

    Change Screen Resolution of An Ubuntu VM in Hyper-V

    Updated:May 2, 20222 Mins Read

    Download Ubuntu 22.04 – DVD ISO Images

    Updated:May 7, 20222 Mins Read

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    How To Install Python 3.10 on Debian 11/10

    2 Mins Read

    How to Install Python 3.10 on CentOS/RHEL 8 & Fedora 35/34

    Updated:February 12, 20223 Mins Read

    How To Install Python 3.10 on Ubuntu, Debian & Linux Mint

    Updated:April 22, 20222 Mins Read

    9 Comments

    1. Alexandre on September 10, 2019 11:30 pm

      Many thanks Rahul, for sharing it with us.

      Great Job.!

      Best Regards,

      Alexandre

      Reply
    2. Udbhav on August 4, 2019 5:55 am

      The browser 192.168.1.239:8000 was not working for me.
      After some research, I added ‘localhost’ to the ALLOWED_HOSTS. It worked 🙂

      Reply
    3. Dleza on July 31, 2019 7:48 pm

      Thank you for this tutorial. its almost perfect.

      Reply
    4. Parmeshwar Kumar Sahu on July 13, 2019 12:24 pm

      Dear Rahul,
      I’m also stucked as couldn’t get the admin page in browser. Please help

      Regards,
      Parmeshwar Sahu

      Reply
    5. Maduka Jayalath on June 29, 2019 5:36 am

      Thanks,

      This one also might be useful for someone https://askubuntu.com/questions/643417/message-cannot-find-installed-version-of-python-django-or-python3-django

      Reply
    6. morrgan on May 31, 2019 2:12 pm

      awesome article

      Reply
    7. Oleks on May 29, 2019 3:57 pm

      Thanks mate! Great instructions 🙂

      Reply
    8. Larisa on May 21, 2019 2:59 pm

      Hi Rahul, I used this web instructions to install Django on my VM ubuntu 16, Every step was done correctly, funally I open Firefox and typed this IP (192.168.1.239: 8000) – I can not connect, here is connection time out. Please advice me what I can do here. Please respond me as soon as possible, thank you.
      Also, I’d liked to ask you: can I load my real browser pages (real project) to Django , do modification, check my new code… and so on – I’m sure you understand what I mean.
      Please respond me,
      Thank you very much in advance.
      Best Regards,
      Larisa.

      Reply
      • Pradeep on May 22, 2020 9:36 am

        add IP address “0.0.0.0” and run 0.0.0.0:8000

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.