Hi there, we’re Harisystems

"Unlock your potential and soar to new heights with our exclusive online courses! Ignite your passion, acquire valuable skills, and embrace limitless possibilities. Don't miss out on our limited-time sale - invest in yourself today and embark on a journey of personal and professional growth. Enroll now and shape your future with knowledge that lasts a lifetime!".

For corporate trainings, projects, and real world experience reach us. We believe that education should be accessible to all, regardless of geographical location or background.

1
1

Setting Up Django: A Step-by-Step Guide

Introduction

Django is a powerful Python web framework that allows developers to build robust web applications with ease. In this guide, we will walk you through the process of setting up Django on your machine and getting started with a basic project.

Step 1: Installing Django

To begin, you need to install Django on your system. Open your terminal and run the following command:

pip install Django

This command will download and install the latest version of Django.

Step 2: Creating a Django Project

Once Django is installed, you can create a new Django project. In your terminal, navigate to the directory where you want to create your project and run the following command:

django-admin startproject myproject

This will create a new directory named "myproject" with the necessary files and folders for your Django project.

Step 3: Running the Development Server

Now, move into the project directory by running:

cd myproject

Inside the project directory, you can start the development server by running the following command:

python manage.py runserver

This will start the development server, and you should see a message indicating that the server is running.

Step 4: Creating an App

In Django, an app is a self-contained module that represents a specific functionality of your project. To create a new app, run the following command:

python manage.py startapp myapp

This will create a new directory named "myapp" inside your project, which will contain the files for your app.

Step 5: Configuring the App

To configure the app, you need to make some changes in the project settings. Open the settings.py file inside the "myproject" directory and add the name of your app (myapp) to the INSTALLED_APPS list.


INSTALLED_APPS = [
    ...
    'myapp',
    ...
]
    

Step 6: Creating Views and Templates

In Django, views handle the logic of your application and templates define the HTML structure. Inside the "myapp" directory, create a new file called views.py and define a simple view:


from django.shortcuts import render
from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello, Django!")
    

Next, create a new directory called "templates" inside the "myapp" directory. Inside the "templates" directory, create a new HTML file called hello.html and add the following content:


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Hello Django</title>
</head>
<body>
    <h1>Hello, Django!</h1>
</body>
</html>
    

Step 7: Mapping URLs

To map URLs to views, open the urls.py file inside the "myproject" directory and add the following code:


from django.urls import path
from myapp.views import hello

urlpatterns = [
    path('hello/', hello),
]
    

Step 8: Testing the Application

Finally, start the development server again by running python manage.py runserver. Open your browser and navigate to http://localhost:8000/hello/. You should see the "Hello, Django!" message displayed.

Conclusion

Congratulations! You have successfully set up Django on your machine and created a basic Django project. Now you can start building powerful web applications using Django's rich set of features.

4.5L

Learners

20+

Instructors

50+

Courses

6.0L

Course enrollments

4.5/5.0 5(Based on 4265 ratings)

Future Trending Courses

When selecting, a course, Here are a few areas that are expected to be in demand in the future:.

Beginner

The Python Course: Absolute Beginners for strong Fundamentals

By: Sekhar Metla
4.5 (13,245)
Intermediate

JavaScript Masterclass for Beginner to Expert: Bootcamp

By: Sekhar Metla
4.5 (9,300)
Intermediate

Python Coding Intermediate: OOPs, Classes, and Methods

By: Sekhar Metla
(11,145)
Intermediate

Microsoft: SQL Server Bootcamp 2023: Go from Zero to Hero

By: Sekhar Metla
4.5 (7,700)
Excel course

Future Learning for all

If you’re passionate and ready to dive in, we’d love to join 1:1 classes for you. We’re committed to support our learners and professionals their development and well-being.

View Courses

Most Popular Course topics

These are the most popular course topics among Software Courses for learners