0% found this document useful (0 votes)
9 views23 pages

Abc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

Abc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Certificate

This is to certify that Digvijay Singh has successfully completed an internship on "Python
with Django Framework" at Soft Pro India from 15th July 2024 to 29th August 2024. During
this internship, Digvijay Singh demonstrated excellent skills in Python programming and
the Django framework, actively contributing to the design and development of web
applications. The internship involved working on real-world projects, gaining hands-on
experience in web development, and understanding the deployment of scalable and
efficient web solutions. We appreciate the dedication, enthusiasm, and commitment
shown by Digvijay Singh throughout the internship period. We wish them all the best for
their future endeavours.

Date:

Dr. Prakash Kumar Singh (HoD) Ms. Yashi Asthana (Mentor)


(CSE Department) (Softpro India)

(i)
Declaration

I, Digvijay Singh, a student of Bachelor of Technology (B.Tech) at Rajkiya Engineering


College Mainpuri, hereby declare that the internship project titled "Python with Django
Framework" is an original work carried out by me during my internship at Soft Pro India.
This project has been completed under the guidance of [Ms. Yashi Asthana and is
submitted in partial fulfilment of the requirements for the successful completion of the
internship program. I confirm that the work presented in this project is genuine, and all
resources or references used have been duly acknowledged. I have not plagiarized or
submitted this work elsewhere for academic or professional purposes. I extend my
gratitude to Soft Pro India for providing me with this opportunity and the necessary
resources to enhance my knowledge and skills in Python and the Django framework.

Date:

Digvijay Singh
CSE 4th Year
2108400100024

(ii)
Acknowledgment

I would like to express my sincere gratitude to Soft Pro India for providing me with the
opportunity to complete my internship on Python with Django Framework. This
internship has been an invaluable learning experience, allowing me to enhance my
technical skills and gain hands-on experience in web development. I am deeply thankful
to Ms. Yashi Asthana, my mentor, for their guidance, support, and encouragement
throughout the internship. Their expertise and insights have been instrumental in helping
me understand the intricacies of Python programming and the Django framework. I also
extend my heartfelt thanks to the entire team at Soft Pro India for creating a collaborative
and supportive environment. Their assistance and feedback have played a crucial role in
the successful completion of my internship. Lastly, I would like to thank my institution,
Rajkiya Engineering College Mainpuri, and my faculty members for their continuous
support and for encouraging me to pursue this internship, which has significantly
contributed to my personal and professional growth.

Digvijay Singh
(Rajkiya Engineering College Mainpuri)

(iii)
Contents

1.Introduction………………………………………………………………. (1)
1.1 Overview of Industry
1.2 Company Profile
1.3 Company History

2. Project Description………………………………………………………..(2)
2.1 Objective
2.2 Scope
2.3 Features

3. Methodology……………………………………………………………(4)
3.1 Tools and technologies Used
3.2 Development process
3.3 Data sources

4. Implementation…………………………………………………………(5)
4.1 Architecture and Design
4.2 Code snippet
4.3 Challenges Faced

5. Learning and Experience………………………………………………...(6)


5.1 Learning Outcomes
5.2 Professional Experience
5.3 Personal Growth

6. Conclusion……………………………………………………………….(

7. Bibliography…………………………………………………………….
Introduction

1.1 Overview of the Industry


The software development industry is at the forefront of technological innovation,
driving advancements in automation, digital transformation, and artificial
intelligence. Web development, a significant subset of the software industry, has
seen rapid evolution with the advent of frameworks that simplify and accelerate the
development process.
Python, a versatile and widely used programming language, has become a
cornerstone of modern web development. Its simplicity, readability, and extensive
library support make it a preferred choice for developers worldwide. The Django
framework, built on Python, is particularly renowned for its "batteries-included"
approach, providing developers with tools and features to build secure, scalable, and
maintainable web applications efficiently.
The demand for web applications has surged across industries, ranging from e-
commerce and healthcare to education and entertainment. Organizations require
robust and dynamic platforms to engage users and manage operations seamlessly.
Frameworks like Django empower developers to meet these demands by offering
tools for rapid development, scalability, and security, making it a vital skill in the
current job market.

1.2 Company Profile


Soft Pro India is a leading IT training and development company committed to
empowering individuals and organizations with cutting-edge technological
expertise. Established with a vision to bridge the gap between academic learning
and industry requirements, Soft Pro India specializes in providing hands-on training
and real-world project experience in various domains of software development.
The company offers a wide range of training programs, including Python, Django,
machine learning, data science, and full-stack web development. With state-of-the-
art infrastructure, experienced mentors, and a focus on practical learning, Soft Pro
India ensures that its trainees are industry ready.
Soft Pro India is also engaged in software development projects, offering
customized solutions to businesses across different sectors. Its emphasis on quality,
innovation, and client satisfaction has earned it a reputation as a trusted partner
for IT training and development.

(1)
1.3 Company History
Founded in 2004, by a team of Technocrats, Soft Pro India started as a small training
institute with a mission to equip aspiring developers with the skills required to thrive in
the IT industry. Over the years, the company has expanded its offerings, incorporating
the latest technologies and methodologies to keep pace with industry trends.
Soft Pro India has trained thousands of students and professionals, many of whom have
gone on to achieve successful careers in leading IT companies. The company’s
development wing has also delivered numerous successful projects, ranging from web
applications to enterprise software solutions.
With a focus on fostering innovation and excellence, Soft Pro India continues to grow,
shaping the future of IT professionals and contributing to the development of the
software industry.

(2)
Project Description

2.1 Objective
The primary objective of this project is to design and develop a scalable, secure, and
user-friendly real-time chat application using the Django framework. The application
aims to enable seamless communication between users, supporting instant
messaging with features like user authentication, group chats, and notifications.

2.2 Scope
This project focuses on implementing real-time communication using Django and
Django Channels, leveraging Web Sockets for instant message delivery. The
application is designed to cater to various use cases, such as personal messaging,
team collaboration, and customer support systems. The project emphasizes
scalability, performance, and user experience, ensuring it can handle multiple
concurrent users effectively.

2.3 Features
1. User Authentication:
o Secure login and registration system using Django's built-in authentication
framework.
o Password encryption for user data security.

2. Real-Time Messaging:
o Instant message exchange using Web Sockets and Django Channels.
o Typing indicators and message delivery status.

3. Chat Rooms:
o One-on-one private chats and group chat functionality.
o Unique chat room identifiers for secure access.

4. Message History:
o Persistent storage of chat messages in a database.
o Ability to view message history for each chat session.

5. Notifications:
o Real-time notifications for new messages.
o Optional email notifications for offline users.

6. Scalability and Performance:


o Use of Redis as a message broker for handling WebSocket connections.
o Optimized database queries for efficient data retrieval.

(3)
Methodology

3.1 Tools and Technologies Used


The development of the real-time chat application utilized a variety of tools and
technologies to ensure efficiency, scalability, and functionality:

1. Frontend Technologies

• HTML5: For structuring the web pages.


• CSS3: For styling and responsive design.
• JavaScript: For dynamic behaviour and interactivity.
• Bootstrap: For responsive and mobile-first design.

2. Backend Technologies

• Python: The core programming language for backend development.


• Django Framework: For building the web application with robust features and a
structured architecture.
• Django Channels: To enable WebSocket support for real-time communication.

3. Database

• SQLite (during development) and PostgreSQL (for production): For storing user
data and chat history.

4. Real-Time Communication

• Web Sockets: For enabling real-time message exchange.


• Redis: Used as a message broker for handling WebSocket connections and
ensuring scalability.

5. Development and Deployment Tools

• Visual Studio Code: For code editing and debugging.


• Git: For version control and collaboration.
• Docker: For containerizing the application to ensure consistent deployment
environments.
• Heroku: For deploying the application to a cloud platform.

(4)
3.2 Development Process
The project followed an iterative and incremental development approach, ensuring
continuous feedback and improvements. The development process included the
following phases:

1. Requirement Analysis
• Understanding the objectives and scope of the project.
• Identifying the key features and functionalities of the chat application.

2. Design
• Creating wireframes and mock-ups for the user interface.
• Designing the architecture of the application, including database schema
and WebSocket communication flow.

3. Implementation
• Setting up the Django project and configuring Django Channels for
WebSocket support.
• Developing user authentication features using Django’s built-in
authentication system.
• Implementing real-time messaging functionality with Web Sockets and
Redis.
• Building the frontend interface using HTML, CSS, and JavaScript.

4. Testing
• Conducting unit testing for individual components.
• Performing integration testing to ensure seamless interaction between the
frontend and backend.
• Testing scalability and performance under concurrent user loads.

5. Deployment
• Containerizing the application using Docker.
• Deploying the application to Heroku for public access.

(5)
3.3 Data Sources

1. Internal Data
• User information: Usernames, email addresses, and passwords stored
securely in the database.
• Chat data: Messages exchanged between users, along with timestamps and
metadata.

2. External Libraries and APIs


• Django Channels: To handle WebSocket connections.
• Redis: As a message broker for managing WebSocket connections and
message queues.
• Bootstrap: For pre-built responsive design components.

No third-party APIs or external data sources were used for this project. All data was
generated and stored locally within the application.

(6)
Implementation

4.1 Architecture and Design


The architecture of the real-time chat application is designed to ensure scalability,
maintainability, and real-time functionality. It consists of the following key
components:

1. Client-Side (Frontend)
• Built using HTML, CSS, and JavaScript.
• Responsible for rendering the user interface, managing WebSocket
connections, and handling user interactions.

2. Server-Side (Backend)
• Developed using the Django framework.
• Handles user authentication, database interactions, and routing.
• Implements Django Channels for real-time WebSocket communication.

3. WebSocket Communication
• Facilitates real-time message exchange between clients using Django
Channels.
• Redis is used as a message broker to manage WebSocket connections and
ensure efficient communication.

4. Database
• PostgreSQL is used for storing user data, chat history, and other metadata.
• Database schema includes tables for users, chat rooms, and messages.

System Design Diagram


The system is designed with the following layers:
1. Presentation Layer: User interface for accessing the chat application.
2. Application Layer: Django application with routing, views, and business logic.
3. Communication Layer: WebSocket layer for real-time data exchange.
4. Data Layer: Database for persistent storage.

(7)
4.2 Code Snippet

1. Installing daphne

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# add django daphne
'daphne' ,
]

2. Installing channels

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# add django channels
'channels' ,
]

3. Set the ASGI application

import os
from channels.routing import ProtocolTypeRouter
from django.core.asgi import get_asgi_application
django_asgi_app = get_asgi_application()

(8)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ChatApp.settings")
application = ProtocolTypeRouter({
"http": django_asgi_app,
# Just HTTP for now. (We can add other protocols later.)
})
ASGI_APPLICATION = 'ChatApp.asgi.application'

4. chat/urls.py
from django.urls import path, include
from chat import views as chat_views
from django.contrib.auth.views import LoginView, LogoutView
urlpatterns = [
path("", chat_views.chatPage, name="chat-page"),
# login-section
path("auth/login/", LoginView.as_view
(template_name="chat/LoginPage.html"), name="login-user"),
path("auth/logout/", LogoutView.as_view(), name="logout-user"),
]

5. templates/chat/chatPage.htm
<!DOCTYPE html>
<html>
<body>
<center><h1>Hello , Welcome to my chat site ! {{request.user}}</h1></center>
<br>
{% if request.user.is_authenticated %}
<center> Logout the chat Page <a href = "{% url 'logout-user'
%}">Logout</a></center>
{% endif %}
<div
class="chat__item__container"
id="id_chat_item_container"
style="font-size: 20px"
>

(9)
<br />
<input type="text" id="id_message_send_input" />
<button type="submit" id="id_message_send_button">Send
Message</button>
<br />
<br />
</div>
<script>
const chatSocket = new WebSocket("ws://" + window.location.host + "/");
chatSocket.onopen = function (e) {
console.log("The connection was setup successfully !");
};
chatSocket.onclose = function (e) {
console.log("Something unexpected happened !");
};
document.querySelector("#id_message_send_input").focus();
document.querySelector("#id_message_send_input").onkeyup = function (e)
{
if (e.keyCode == 13) {
document.querySelector("#id_message_send_button").click();
}
};
document.querySelector("#id_message_send_button").onclick = function (e)
{
var messageInput = document.querySelector(
"#id_message_send_input"
).value;
chatSocket.send(JSON.stringify({ message: messageInput, username :
"{{request.user.username}}"}));
};
chatSocket.onmessage = function (e) {
const data = JSON.parse(e.data);
var div = document.createElement("div");
div.innerHTML = data.username + " : " + data.message;

(10)
document.querySelector("#id_message_send_input").value = "";
document.querySelector("#id_chat_item_container").appendChild(div);
};
</script>
</body>
</html>

6. chat/consumers.py

import json
from channels.generic.websocket import AsyncWebsocketConsumer
class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.roomGroupName = "group_chat_gfg"
await self.channel_layer.group_add(
self.roomGroupName ,
self.channel_name
)
await self.accept()
async def disconnect(self , close_code):
await self.channel.name.group_discard(
self.roomGroupName ,
self.channel_name
)
async def receive(self, text_data):
text_data_json = json.loads(text_data)
message = text_data_json["message"]
username = text_data_json["username"]
await self.channel_layer.group_send(
self.roomGroupName,{
"type" : "sendMessage" ,
"message" : message ,
"username" : username ,
})

(11)
async def sendMessage(self , event) :
message = event["message"]
username = event["username"]
await self.send(text_data = json.dumps({"message":message
,"username":username}))

Outputs:

(12)
(13)
4.3 Challenges Faced

1. WebSocket Integration
• Challenge: Setting up WebSocket communication with Django Channels
required a deep understanding of asynchronous programming.
• Solution: Thorough research and testing were conducted to configure
Django Channels and Redis properly.

2. Handling Concurrent Users


• Challenge: Ensuring the application could handle multiple users in real-time
without performance degradation.
• Solution: Redis was used as a message broker, and the application was
stress-tested to optimize performance.

3. Persistent Message Storage


• Challenge: Designing a database schema that efficiently stores and retrieves
chat messages.
• Solution: A normalized database schema was implemented, and queries
were optimized for better performance.

4. Deployment Issues
• Challenge: Deploying the application with WebSocket support on Heroku.

• Solution: Docker was used to containerize the application, and Heroku


configurations were adjusted to support ASGI applications.

5. Real-Time Notifications
• Challenge: Implementing real-time notifications for new messages without
overloading the system.
• Solution: Efficient WebSocket event handling and client-side updates were
implemented.

(14)
Learning and Experience

5.1 Learning Outcomes


During developing the real-time chat application using Django, I gained valuable
insights and skills that significantly enhanced my technical and professional abilities:
1. Mastery of Python and Django
• Deepened my understanding of Python programming and the Django
framework, particularly its Model-View-Template (MVT) architecture.
• Learned to leverage Django’s built-in features, such as authentication, ORM, and
admin interface, for efficient development.
2. Real-Time Communication
• Acquired hands-on experience in implementing WebSocket-based real-time
communication using Django Channels.
• Understood the role of asynchronous programming in managing concurrent
connections effectively.
3. Database Management
• Gained experience in designing and managing relational databases using SQLite
and PostgreSQL.
• Learned how to structure and optimize database schemas for storing chat data
efficiently.
4. Deployment and Scalability
• Understood the challenges and best practices of deploying Django applications
with WebSocket support on cloud platforms like Heroku.
• Learned to use Docker for containerization, ensuring consistent deployment
environments.
5. Frontend Integration
• Improved my skills in frontend development using HTML, CSS, and JavaScript.
• Learned to integrate the frontend with the backend for a seamless user
experience.
6. Debugging and Testing
• Gained proficiency in debugging complex issues related to asynchronous
operations and WebSocket communication.
• Conducted unit and integration testing to ensure the reliability of the
application.

(15)
5.2 Professional Experience
This internship provided me with a professional environment to apply theoretical
knowledge to practical problems.
1. Team Collaboration
• Worked under the guidance of experienced mentors, which enhanced my
ability to follow industry best practices.
• Learned to communicate effectively and collaborate with team members to
achieve project goals.
2. Time Management
• Developed time management skills by adhering to project deadlines and
milestones.
• Balanced multiple tasks, including learning new concepts, coding, testing,
and debugging.
3. Problem-Solving
• Encountered and resolved real-world challenges, such as handling
concurrent WebSocket connections and optimizing database queries.
• Improved my ability to research, analyse, and implement effective
solutions.
4. Adaptability
• Adapted to new tools and technologies, such as Redis and Docker, which
were unfamiliar at the start of the internship.
• Quickly learned and applied concepts like asynchronous programming and
message brokering.

5.3 Personal Growth


In addition to technical and professional skills, this project contributed to my
personal growth:
• Boosted my confidence in tackling complex development tasks independently.

• Enhanced my ability to learn new technologies and adapt to evolving


requirements.
• Strengthened my problem-solving mindset and persistence in overcoming
obstacles.

(16)
Conclusion

The development of the Real-Time Chat Application using Django as part of my


internship on Python with the Django framework has been an enriching and
transformative experience. This project not only enhanced my technical skills but also
provided valuable insights into the practical aspects of software development.

The primary objective of the project was to design and implement a functional,
scalable, and secure real-time chat application. By leveraging Django and Django
Channels, the application successfully achieved features such as user authentication,
real-time messaging, and persistent chat history. The integration of Web Sockets for
instant communication and Redis as a message broker further ensured seamless and
efficient performance, even with concurrent users.

This project helped me gain a deeper understanding of the Django framework and its
ecosystem, including asynchronous programming, database management, and
deployment strategies. It also improved my problem-solving abilities, as I encountered
and resolved challenges such as WebSocket integration, database optimization, and
deployment issues on cloud platforms.

In addition to technical learning, the internship provided a professional environment to


develop essential soft skills, including teamwork, time management, and adaptability.
The experience of working on a real-world project has prepared me to handle complex
software development tasks confidently in the future.

(17)
References

1. Books and Documentation


o Django Software Foundation. Django Documentation (Version 4.x).
https://docs.djangoproject.com/

o Python Software Foundation. Python Documentation.


https://docs.python.org/

o Celery Project. Celery Documentation.


https://docs.celeryproject.org/

o Redis. Redis Documentation.


https://redis.io/documentation

2. Web Articles and Tutorials


o Real Python. Introduction to Django Channels and Web Sockets
https://realpython.com/

o Digital Ocean. How to Set Up Django with Postgres, Nginx, and Gunicorn on
Ubuntu.
https://www.digitalocean.com/community/tutorials

o Mozilla Developer Network (MDN). WebSocket API Documentation.


https://developer.mozilla.org/

3. Research Papers and Articles


o Tanenbaum, A. S., & Van Steen, M. Distributed Systems: Principles and
Paradigms. Pearson Education.

o W3C. WebSocket Protocol Specification.


https://www.w3.org/

4. Community Support
o Stack Overflow. Django and WebSocket Development Discussions.
https://stackoverflow.com/

o GitHub. Open Source Repositories for Django Projects.


https://github.com/

(18)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy