Django is a Python-based free and open-source web framework that follows the model–template–views architectural pattern. In this tutorial, I will show you how to start a new project in Django and print hello world.
Before jumping this tutorial, first, you have installed python and other stuff. Using this command
python --version check you’ve to install python or not. After installing python, then you have to install pip. PIP is a package management system used to install and manage software packages written in Python. It stands for “preferred installer program” or “Pip Installs Packages.” PIP for Python is a utility to manage PyPI package installations from the command line.
python --version // Python 3.8.10 pip --version // pip 21.3.1 from /home/shahin/.local/share/virtualenvs/dg2-TOnqnzTa/lib/python3.8/site-packages/pip (python 3.8)
To ensure pip and python then you have to install pipenv. Pipenv is a packaging tool for Python that solves some common problems associated with the typical workflow using pip, virtualenv , and the good old requirements. txt. In addition to addressing some common issues, it consolidates and simplifies the development process to a single command-line tool.
Read More : Implement selection sort algorithm using python
pip install pipenv
Well, after installing pipenv, create a folder for your project. Let’s have a look at the following commands and run them step by step. I assume you are in the desktop folder.
mkdir project // create a folder for project cd project // go to project folder
Well, after reaching the project folder then run the following command.
pipenv install django
Using this command, you have to install Django in your project. After then you’ve to run this command. After successfully executing this command you can see two files in your project folder. One is pipfile another one is pipfile.lock
Using this command you can make a virtual environment for your project. Well after then you have to create a Django project.
django-admin startproject project_name .
Using this command, you can create a project that is your root project. Inside this root project, you can see a couple of flies. Also, create another file that is manage.py.
Well, after using this command, you can serve your project. Hit this following command, it will give you a development server link. Copy this link and paste your favorite browser.
python manage.py runserver
http://127.0.0.1:8000/ hit this URL and get like this interface.
Hurry! you’ve successfully installed the Django project on your machine. Now you can create an app for your application. To create an app you have to run this command.
python manage.py startapp app_name
After creating an app, then you have to register the app name in your root’s settings.py file. You have to register INSTALLED_APPS list like this.
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'frontend' // your custom app ]
Hopefully, this tutorial will help you.