Django is one of the best and very popular web application framework of Python. in this article we will share with you how to install Django in your ubuntu system and how to run your first python web application in a web browser. Django provides us hight security in web application and it also provides many ready-made helper it's can help us to build web applications very fast.
This article will help you to install Django in ubuntu OS and how to run your first python web application in your web browser.
Before installing Django you should install python, the following link helps you in install python.
Ubuntu 16.04 have installed python 2 by default. but we need to python 3. so, first wee need to install python 3 in our ubuntu system. run the following command in your terminal to install pip.
sudo apt-get install python3 python3-pip
The installed Python version is:
python3 -V Python 3.5.3
The installed PIP version is:
pip3 -V pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
Django is open-source and is also available on GitHub you can download from there using
pip and install
Django in your ubuntu system. in this article I use
pip3 for the installation of Django in ubuntu. run the following command in the terminal.
pip3 install Django
django-admin --version 2.2.6
Now, we will show how to create our first
Django application in our ubuntu system. the
django-admin command provides us to create one new fresh
django application. you can create an application anywhere in your system directory. just go to your right path and run the following command in terminal.
cd /var/www django-admin startproject first_django_app
After, create your first
Django the application then we should run the default migration help of the following command in your terminal.
cd first_django_app python3 manage.py migrate
Now, we need to create one
SuperUser / Admin for the administration of the Django web application. run the following command on your project root directory for creating
SuperUser / Admin.
python3 manage.py createsuperuser
Now, your Django application ready to run and use. by default Django not allow any external hosts to access or run Django application in a web browser. so first we add some hosts in
first_django_app/settings.py a file. just change the following code line and add hosts that use to run the Django application. I mostly use
localhost to run any web application. so, I will add my
localhost host in
settings.py a file.
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['192.168.1.104' , 'localhost']
look above changes I added my two hosts there. so I will able to run my Django web application on both hosts
localhost. now run the following command for run the Django web application in our web browser.
python3 manage.py runserver 192.168.1.104:8000 //Or python3 manage.py runserver localhost:8000
After, hit above command in your terminal then now open
http://localhost:8000 URL in your browser to run the Django application. after a run, it looks like the following screenshot.
Django's By default admin route is
Then enter your username and password there. which we created in
Step - 4. after login as a
SuperUser the screen looks like.
We hope you like this article.
Laravel 8 Send Mail using MailtrapToday, I would relish to show you larave...
Build a Basic React AppIn this article, we will share with you...
How to Install Sublime Text 4 on UbuntuSublime text is powerful, lightweight an...
VueJs CRUD Example using MongoDB | Express.js | Vue.js | Node.jsThis is a step by step MEVN stack tutori...
Laravel 5.5 - The page has expired due to inactivity - issueToday, we are share with you how to reso...