Getting Started with Django: A Step-by-Step Guide

Rex Cole
2 min readDec 30, 2023

--

If your system uses python3 instead of python for Python 3, you can simply replace the commands in the instructions with python3 where needed. Here's the modified set of instructions:

Step 1: Install Django

If you haven’t installed Django yet, use the following command to install it:

pip3 install django

Step 2: Create a Django Project

Run the following command to create a new Django project. Replace “yourprojectname” with the desired name for your project.

django-admin startproject yourprojectname

Step 3: Navigate to the Project Directory

Change into the project directory using the cd command:

cd yourprojectname

Step 4: Create a Django App

A Django project is made up of one or more apps. Create an app using the following command. Replace “yourappname” with the desired name for your app.

python3 manage.py startapp yourappname

Step 5: Configure Database

Open the settings.py file in your project folder and configure the database settings. By default, Django uses SQLite. You can change it to another database like PostgreSQL, MySQL, or others.

Step 6: Run Migrations

Django uses migrations to create database tables based on your models. Run the following commands to apply migrations:

python3 manage.py makemigrations
python3 manage.py migrate

Step 7: Create a Superuser (Optional)

If you want to use the Django admin interface, create a superuser account with the following command:

python3 manage.py createsuperuser

Follow the prompts to create a superuser account.

Step 8: Run the Development Server

Start the development server to see if everything is set up correctly:

python3 manage.py runserver

Open your web browser and go to http://127.0.0.1:8000/ to see your Django project.

Step 9: Create Views, Templates, and Models

Build your application by defining views, creating templates, and designing models. Add business logic to your app.

Step 10: Test Your App

Create tests for your application to ensure it functions correctly:

python3 manage.py test

Step 11: Run Your App

After developing your app, run it using the development server:

python3 manage.py runserver

Access your app in the browser and test its functionality.

Step 12: Deploy to Production (Optional)

If you’re ready to deploy your Django app to a production environment, consider using a production-ready server like Gunicorn or uWSGI, and a web server like Nginx or Apache.

--

--

No responses yet