There is so many tools and programming languages to code for web whether it is front-end or back-end for example PHP and JavaScript ,django and flask. in this blog we are going to talk about django so what is Django? Django is a free and open-source Python back-end web framework that removes the tedium of building websites by providing most of the required behavior. it has a collection of components that are designed to work together, and they cover many of the common areas of web development. An important aspect of Django is that many of its components are independent and, therefore, can be used individually without having to load all of them.also Django follows the Don’t Repeat Yourself (DRY) principle. so that means you will never need to repeat your code and most of all Django is a framework whose main goal is perfection. now how to setup your Django environment? well today i'm going to show how to do it
1- Configuring the environment on your device :
The first step to take is to install the latest version of Python you can download it from this link https://www.python.org/ .
After downloading it you install it by just double clicking on the setup you will get a window like this
make sure to add check the add python to environment variables button after clicking next as shown below :
The second thing you need to do after installing python is to an isolated environment, now create a folder with the name you desire in any location then open the cmd if you are working in Windows or shell in Linux then log to that folder you created and enter the commend that will create the isolated environment like below:
python -m venv my_DJ_project
This will create a my_DJ_project/ directory, including your Python environment (you will see folders like the one below).
now you need to activate this latter by entering to that folder (my_DJ_project ) with cmd and then enter to script folder after that you activate the environment with the activate.bat file (you can deactivate it by entering deactivate.bat in cmd) after activating it, it should look like the image below in your cmd
now all our installed packages will be installed in this environment and not globally.
In this step you need to install Django with the pip tool that comes shipped with the python setup. So to install this latter you ought to enter the following commend in the activated environment as shown in the picture
python -m pip install Django==3.0.5
Now we are done from setting the development environment
2- Creating the project:
Django comes shipped with with tools that allow you to do so .Now create another folder in my_DJ_project enter in it with cmd and run the following command from your cmd:
django-admin startproject MyProject
This will create a Django project with the name MyProject.
Now it is time to start the Django server with the following commend
python manage.py runserver
You should see something like this in your cmd
Now open your browser and in the URL bar enter http://127.0.0.1:8000/ . it should say that the project is successfully running, as shown in the picture below:
3- Creating an application
Now let's create Django application. From the project's root directory, run the following command you can specify the name of application as you desired :
python manage.py startapp myApp
We are done creating the application now you can start code the app you desire to create