Build Your First Django App: Beginner's Guide

doreen970

DoreenNangira

Posted on November 18, 2023

Build Your First Django App: Beginner's Guide

Django is a Python framework that has been here for quite a while. Due to its robust nature and impressive features, many developers have made it the framework of their choice. However, most beginners find it challenging to get started with Django but worry not. I am here to hold your hand and walk you through this amazing journey. So, let's get started!

Prerequisite

python knowledge: You need to have basic knowledge of python such as syntax, python functions and python classes.
Download python: Download and install python in your machine. Navigate to Python.org and get the official version for your machine whether windows, macOS or Unix. To check if python is already installed, write python --version on your terminal or command-line. This will show you your python version.
Install pip: pip is a python package manager that we will use throughout our project to install various features and packages. To install pip, follow the instructions provided on the official Python website, Installing with get-pip.py.
IDE: IDE stands for Integrated Development Environment. This is where we will write our code. Make sure you have one installed. You can use IDE of your choice such as Visual Studio Code, PyCharm etc.

Development

1.Create a folder that will host your Django project.

  1. Create a virtual environment. When dealing with Django, it is always advisable to create an isolated environment to host different Django projects. This is in order to maintain consistency and avoid future conflicts especially with your project dependencies. windows users: navigate to the directory you created then use the command py -m venv myenv. myenv is the name of our virtual environment. Unix/MacOS: python -m venv myenv.
  2. Activate virtual environment Windows: myenv\Scripts\activate.bat Unix/MacOS: source myenv/bin/activate Once the virtual environment is active, you will see the name of your virtual environment displayed and enclosed in brackets. eg(myenv)
  3. Install Django Run the command pip install Django. Make sure you do this while in activated virtual environment.
  4. Create a Django project You need a name for your Django project. After coming up with a suitable name, run django-admin startproject project_name . project_name is the name of your project. Please note the dot(.) at the end after project name. This ensures that Django does not create two instances of your project name. Whenever you leave out the dot the name will appear twice and this can be confusing to beginners. Open your Django project folder and you will see some files in it such as urls.py, wsgi.py etc. This shows you you have a Django project now.
  5. Run your Django project While still in the root folder of your project, write python manage.py runserver and press enter. This will start the Django development server. Copy the url or address you get and paste it in your browser. If everything is well, you will see the following image.

picture of a successfully running Django project
Good! You now have a Django project. To quit the development server press CTRL+C on your keyboard.

This is the end of our first series of the tutorial. We will continue with the next steps in the next tutorial.
See you soon, Adios!!

馃挅 馃挭 馃檯 馃毄
doreen970
DoreenNangira

Posted on November 18, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related