Getting Started with Django
Basic start with the Django Python Framework
A step-by-step guide to create your first Django project.
Let's first create a folder on our desktop or wherever you want.
- Open your terminal and type the command
cd Desktopto navigate to your desktop.
- To create a new folder and name it "first_project", type the command
- Navigate into that folder by typing the command
- Then to open that new folder in your text editor, type the command
It will then open in your
default text editor.
The next step is to install django, but before we do that, we have to first make sure that we have python and pip installed on our machines.
- In your text editor, open the terminal and cd to your current folder
- To check if python is installed, type the command
python --versionin your terminal. It will return the python version that is installed.
- If its not installed, type
python.orgin your browser to go through the python installation process.
- Then let's check and see if pip is installed by typing the command
pip --versionIt will return the version of pip installed.
- Let's now run the command
pip install djangoto install Django.
Creating a Django Project
- To create a Django project, let's type the command
django-admin startproject <project-name> .
- Let's name it
config, and so we will run
django-admin startproject config .
- We include
<space> .at the end, to install all the dependencies that our app will need to run properly.
- You will then realize that a new folder
confighas been created within our project and some other files inside it.
- The files are:
settings.pyis where we add all the different folders for the different products of our application.
urls.pyis where we add url patterns for our views.
wsgi.pyare not to be touched until we reach the stage of deployment.
manage.pytakes control of all the things we are to run.
Running our Django Application
- To run our django application, let's type the command
runserverto run the server into the browser.
- Follow the link in your terminal and boom!!!!!
Software Engineer | Data Scientist | Cloud Engineer | Content Writer