To build web applications with Django, it is essential to have Python installed on your machine beforehand. However, having Python installed is not enough, you also need to install Django, write a few lines of code and run the application with Django. How do I get started with Django?
Norton Secure VPN 2023 for up to 5 Devices | |
19,99 $ |
Requirement
- An internet connection
- The basics of Python
- Good judgement
- A minimum of concentration and attention
- Knowledge of the command prompt
Getting started with Django
Before we get started, do you have what you need to get started with Django? If so, let’s get down to business.
- Open a terminal: move to the directory where you want to create your Django project
- Once in that directory, create a virtual environment and activate it
- Install Django by entering the command “pip install Django
- Save the new packages in the “requirements.txt” file with the “pip freeze > requirements.txt” command
NB : your virtual environment must be activated, also make sure you are in the root directory where your virtual environment is located, also respect the spaces between the words of the commands.
You will notice that there are changes in the base directory of your project; open it for example with your integrated development environment to see the changes. You will see a tree structure similar to this
Now we have to check that our application is running,
- Go to the mysite sub-directory and type the command
You will get an output similar to the image below in your command prompt
- Go to the doc
By default, Django comes with an authentication system and many other features. We therefore need to create the corresponding databases for this authentication system through what are called migrations.
- Run the command
Django works with a set of mini applications for a single project; it’s time to generate our first mini application
- Then run the command
- Fill in the mini application in settings.py as shown here:
If you wish to configure a DBMS other than SQLite which is delivered with Django, go to the mysite subdirectory, then in settings configure the new DBMS you wish to use by modifying parameters such as ENGINE, NAME, USER, PASSWORD, HOST. For the database you are going to use, go to the official documentation to find out how to configure it.
You have everything you need to start creating templates and returning data from these templates using a view. For the creation of models and views, please read the documentation, or follow this course.
Find out about :
- Why and How to use two VPN’s on the same device
- How to create your own free online TV channel- Web TV