Getting Started with Django

Getting Started with Django

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 Desktop
    

    to navigate to your desktop.

  • To create a new folder and name it "first_project", type the command

    mkdir first_project
    
  • Navigate into that folder by typing the command

    cd first_project
    
  • Then to open that new folder in your text editor, type the command code .

It will then open in your default text editor.

Install Django

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

    cd first_project
    
  • To check if python is installed, type the command python --version in your terminal. It will return the python version that is installed.

  • If its not installed, type python.org in your browser to go through the python installation process.

  • Then let's check and see if pip is installed by typing the command

    pip --version
    

    It will return the version of pip installed.

  • Let's now run the command

    pip install django
    

    to 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 config has been created within our project and some other files inside it.

  • The files are:

fy.PNG

  • settings.py is where we add all the different folders for the different products of our application.

  • urls.py is where we add url patterns for our views.

  • asgi.py and wsgi.py are not to be touched until we reach the stage of deployment.

  • manage.py takes control of all the things we are to run.

Running our Django Application

  • To run our django application, let's type the command

    python manage.py runserver
    

    to run the server into the browser.

  • Follow the link in your terminal and boom!!!!!

yt.PNG