Abc
Abc
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:
(i)
Declaration
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
6. Conclusion……………………………………………………………….(
7. Bibliography…………………………………………………………….
Introduction
(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.
(3)
Methodology
1. Frontend Technologies
2. Backend Technologies
3. Database
• SQLite (during development) and PostgreSQL (for production): For storing user
data and chat history.
4. Real-Time Communication
(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.
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
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.
(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' ,
]
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.
4. Deployment Issues
• Challenge: Deploying the application with WebSocket support on Heroku.
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
(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.
(16)
Conclusion
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.
(17)
References
o Digital Ocean. How to Set Up Django with Postgres, Nginx, and Gunicorn on
Ubuntu.
https://www.digitalocean.com/community/tutorials
4. Community Support
o Stack Overflow. Django and WebSocket Development Discussions.
https://stackoverflow.com/
(18)