Django Report
Django Report
Report
On
Summer Internship
Under the guidance of
Department of Computer Science and Engineering
(Artificial Intelligence and Machine Learning)
MBM University
Air Force Area, Jodhpur, Rajasthan 342011
Submitted by
Kanchan Kumari
Roll No. : 22UBAML4104
Submitted to
Ms. Divya Khatri
Branch Coordinator
Dept. of Computer Science and Engineering
(Artificial Intelligence and Machine Learning)
Engineering College Barmer
CERTIFICATE
i
CERTIFICATE
ii
ACKNOWLEDGEMENT
First I would like to thank the Ms. Divya Khatri , Branch Coordinator(AI&ML)
of Engineering College Bramer for giving me the opportunity to do an internship within
the University.
It is indeed with a great sense of pleasure and immense sense of gratitude that I acknowl-
edge the help of these individuals.
I am highly indebted to our Principal Dr. S.K. Bishnoi and Engineering College
Barmer for the facilities provided to accomplish this internship.
I would like to thank my Branch Coordinator Ms. Divya Khatri for her support and
guidance.
I would like to thank Our faculty Mr. Deepak Van for his constructive criticism
throughout my internship.
Grateful to:
• Binary Club.
iii
ABSTRCT
This project focuses on the development of a web application using the Django frame-
work, a powerful and versatile tool for building dynamic websites and web applications.
The main objective of this project is to showcase the capabilities of Django and highlight
its effectiveness in creating robust and scalable web solutions.
The web application, titled "DjangoShop," is designed to simulate an online e-commerce
platform. It encompasses various features such as user authentication, product catalog, shop-
ping cart functionality, order processing, and user profiles. The project demonstrates how
Django’s Model-View-Controller (MVC) architecture, templating system, and integrated
ORM (Object-Relational Mapping) facilitate rapid and efficient development.
Through the implementation of DjangoShop, key aspects of Django’s functionality are
explored, including URL routing, database management, form handling, and user authen-
tication. The project’s codebase adheres to best practices in terms of code organization,
separation of concerns, and security considerations.
Furthermore, the project highlights the versatility of Django by incorporating respon-
sive design principles, allowing the web application to adapt seamlessly to various devices
and screen sizes. This ensures an optimal user experience across desktops, tablets, and
smartphones.
Overall, the DjangoShop project serves as an illustrative example of how Django can be
employed to create a sophisticated and feature-rich web application. It underscores Django’s
role as a preferred choice for developers aiming to build interactive and scalable web solutions
with a focus on maintainability and user-centered design.
iv
Contents
1 Introduction 3
1.0.1 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.0.2 View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.0.3 Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.0.4 URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1 Django Admin Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1.1 Create an Admin User . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Django App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Creating an App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 Django URL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 About project 21
5 Future Scope 23
1
6 Conclusion 25
References 28
2
Chapter 1
Introduction
Django is a Python framework that makes it easier to create web sites using Python.
Django takes care of the difficult stuff so that you can concentrate on building your web
applications.
Django emphasizes reusability of components, also referred to as DRY (Don’t Repeat
Yourself), and comes with ready-to-use features like login system, database connection and
CRUD operations (Create Read Update Delete).
Django follows the MVT design pattern (Model View Template).
• Model - Represents the data you want to present, typically retrieved from a database.
• View - Acts as a request handler, returning the relevant template and content based
on user requests.
• Template - A text file (e.g., HTML) that defines the layout of the web page and
includes logic for displaying the data.
1.0.1 Model
The model provides data from the database.
In Django, the data is delivered as an Object Relational Mapping (ORM), which is a tech-
nique designed to make it easier to work with databases.
The most common way to extract data from a database is SQL. One problem with SQL is
3
that you have to have a pretty good understanding of the database structure to be able to
work with it.
Django, with ORM, makes it easier to communicate with the database, without having to
write complex SQL statements.
The models are usually located in a file called models.py.
1.0.2 View
A view is a function or method that takes http requests as arguments, imports the relevant
model(s), and finds out what data to send to the template, and returns the final result.
The views are usually located in a file called views.py.
1.0.3 Template
A template is a file where you describe how the result should be represented.
Templates are often .html files, with HTML code describing the layout of a web page,
but it can also be in other file formats to present other results, but we will concentrate on
.html files.
Django uses standard HTML to describe the layout, but uses Django tags to add logic:
The templates of an application is located in a folder named templates.
1.0.4 URLs
Django also provides a way to navigate around the different pages in a website.
When a user requests a URL, Django decides which view it will send it to.
This is done in a file called urls.py.
4
Figure 1.2: createsuperuser
interface (/admin/) and access the admin dashboard to manage various aspects of your
application, including database records, users, and other administrative tasks. The superuser
has the highest level of access and can perform actions that regular users cannot.
Remember to keep the superuser credentials secure and follow best practices for password
management.
2. Navigate to the root directory of your Django project (the directory containing the
manage.py file).
5
4. Django will generate a new directory named members within your project’s directory
structure. Inside the members directory, you will find several files and subdirectories
that make up the structure of the new application.
5. The startapp command creates the basic structure for the new application, including
files such as:
6. After creating the new application, you can start building and customizing its func-
tionality by adding code to the various files. Don’t forget to also add your new
application to the INSTALLED_APPS list in your project’s settings.py file to make it
accessible within your project.
# u r l s . py
urlpatterns = [
path ( ’ admin/ ’ , admin . s i t e . u r l s ) ,
]
6
1.2.2 Django URL Functions
7
Chapter 2
Static files are files that don’t change often and are served directly by the web server to the
client’s browser. These files include stylesheets (CSS), JavaScript files, images, fonts, and
other assets that contribute to the visual and functional aspects of a web page.
Django provides a robust way to manage and serve static files while developing and
deploying your web application. Here’s how Django handles static files:
8
2.0.5 Deploying to Production
In a production environment, you’ll need to configure your web server (such as Apache, Ng-
inx) to serve static files directly. When deploying, you can use the collectstatic command
to gather all your static files into a single directory, which can then be served by the web
server. You’ll update the STATIC_URL setting to point to this directory.
9
7. CSRF Protection: Django Forms automatically handle Cross-Site Request Forgery
(CSRF) protection by adding a CSRF token to the form. This helps prevent unau-
thorized submissions from malicious sources.
8. Formsets: Formsets allow you to work with multiple instances of a form on a single
page. This is useful for scenarios like handling multiple related records in a single
form submission.
9. ModelForms: Django provides a convenient way to create forms based on your model
classes. These are known as ModelForms and automatically generate form fields based
on the model’s fields and their data types.
10. Customization and Validation: You can customize the behavior and appear-
ance of forms by defining methods in the form class, such as clean< f ieldname >
()methodsf orf ield − specif icvalidation.
Additionally, youcancreatecustomf ormf ieldsandwidgetsif thebuilt − in
onesdon′ tmeetyourrequirements.
11. File Uploads: Django Forms support file uploads with the FileField and ImageField
fields.
You can handle file uploads like any other form data.
// models.py
from django . db import models
c l a s s Meta :
db_table = " employee "
Now, create a form which contains the below code.
// forms.py
10
2.2.1 Instantiate the form
Instantiate the form, check whether request is post or not. It validate the data by using
isv alid()method.
//views.py
def emp( r e q u e s t ) :
i f r e q u e s t . method == "POST" :
form = EmployeeForm ( r e q u e s t .POST)
i f form . i s _ v a l i d ( ) :
try :
return r e d i r e c t ( ’ / ’ )
except :
pass
else :
form = EmployeeForm ( )
return r e n d e r ( r e q u e s t , ’ i n d e x . html ’ , { ’ form ’ : form } )
Index template that shows form and errors.
11
Start server and access the form.
1. Setting Up a Database:
In your Django project’s settings file (settings.py), you define your database config-
urations. Django supports various database engines such as SQLite, PostgreSQL,
MySQL, and Oracle. You configure your database connection by specifying the
database engine, name, user, password, host, and port.
DATABASES = {
’ default ’ : {
’ENGINE ’ : ’ django . db . backends . s q l i t e 3 ’ ,
’NAME’ : BASE_DIR / ’ db . s q l i t e 3 ’ ,
}
}
2. Defining Models:
Django models are Python classes that define the structure of your data. Each at-
tribute of a model class corresponds to a database column. Django’s ORM automat-
ically generates SQL schema from your model definitions and manages the database
tables for you.
3. Creating Database Tables:
After defining your models, you need to create the corresponding database tables.
Django provides a command-line tool for creating tables based on your model defini-
tions.
python manage . py makemigrations
python manage . py m i g r a t e
12
4. Querying Data:
Django’s ORM allows you to perform database queries using Python methods and
filters, abstracting away the underlying SQL syntax. For example, to retrieve all
employees with a specific last name:
employees = Employee . o b j e c t s . f i l t e r ( last_name =’Smith ’ )
employee . d e l e t e ( )
employees_with_counts =
Employee . o b j e c t s . a n n o t a t e ( num_orders=Count ( ’ o r d e r ’ ) )
with c o n n e c t i o n . c u r s o r ( ) a s c u r s o r :
%s " , [ ’ Smith ’ ] )
employees = c u r s o r . f e t c h a l l ( )
13
These are some of the fundamental aspects of Django’s database connectivity and usage.
Django’s ORM provides many more advanced features, such as model relationships (for-
eign keys, many-to-many), transactions, migrations, and more, which make working with
databases in Django powerful and efficient.
2.3.1 makemigrations
The makemigrations command is used to create a migration file that contains the code
representing the changes to the model’s schema. This command analyzes the current state
of the models and generates the necessary migration code to apply the changes.
2.3.2 migrate
The migrate command is used to apply the changes defined in migration files to the
database. It creates or modifies database tables according to the schema changes speci-
fied in the migration files.
2.3.3 sqlmigrate
The sqlmigrate command provides a way to view the raw SQL queries that would be
executed for a specific migration. This helps you understand the exact SQL statements that
will be used to apply the migration.
2.3.4 showmigrations
The showmigrations command lists all the available migrations along with their status
(applied or not applied). This command is helpful for tracking the history of migrations in
your project.
//models.py
14
from django . db import models
c l a s s Employee ( models . Model ) :
e i d = models . C h a r F i e l d ( max_length =20)
ename = models . C h a r F i e l d ( max_length =100)
e c o n t a c t = models . C h a r F i e l d ( max_length =15)
c l a s s Meta :
db_table = " employee "
To create a migration for this model, use the following command. It will create a mi-
gration file inside the migration folder.
python manage.py makemigrations
15
Chapter 3
The client-server architecture includes two major components request and response. The
Django framework uses client-server architecture to implement web applications.
When a client requests for a resource, a HttpRequest object is created and correspond view
function is called that returns HttpResponse object.
To handle request and response, Django provides HttpRequest and HttpResponse classes.
Each class has it’s own attributes and methods.
16
Attribute Description
scheme A string representing the scheme of the re-
quest (HTTP or HTTPS usually).
body It returns the raw HTTP request body as a
byte string.
path It returns the full path to the requested page,
does not include the scheme or domain.
path_info It shows the path info portion of the path.
method It shows the HTTP method used in the re-
quest.
encoding It shows the current encoding used to decode
form submission data.
content_type It shows the MIME type of the request,
parsed from the CONTENT_TYPE header.
content_params It returns a dictionary of key/value parame-
ters included in the CONTENT_TYPE header.
GET It returns a dictionary-like object containing
all given HTTP GET parameters.
POST It is a dictionary-like object containing all
given HTTP POST parameters.
COOKIES It returns all available cookies.
FILES It contains all uploaded files.
META It shows all available HTTP headers.
resolver_match It contains an instance of ResolverMatch
representing the resolved URL.
17
Attribute Description
get_host() It returns the original host of the request.
get_port() It returns the originating port of the request.
get_full_path() It returns the path, plus an appended query string, if
applicable.
build_absolute_uri(location)It returns the absolute URI form of location.
get_signed_cookie(key, It returns a cookie value for a signed cookie, or raises
default=RAISE_ERROR, a django.core.signing.BadSignature exception if
salt=”, max_age=None) the signature is no longer valid.
is_secure() It returns True if the request is secure; that is, if it
was made with HTTPS.
is_ajax() It returns True if the request was made via an
XMLHttpRequest.
Scaffolding
Bootstrap provides a basic structure with the Grid System, link styles, and background.
CSS
Bootstrap comes with the feature of global CSS settings, fundamental HTML elements style,
and an advanced grid system.
Components
Bootstrap contains a lot of reusable components built to provide iconography, dropdowns,
navigation, alerts, pop-overs, and much more.
JavaScript Plugins
Bootstrap also contains a lot of custom jQuery plugins. You can easily include them all or
one by one.
Customize
Bootstrap components are customizable, and you can customize Bootstrap’s components,
LESS variables, and jQuery plugins to get your own style.
18
Figure 3.1: Bootstrap folder.
19
<html lang=" en ">
<head>
<meta charset="UTF−8">
<t i t l e>l o g i n</ t i t l e>
</head>
<body>
<form action=" / s a v e " method=" p o s t ">
<div c l a s s=" form−group ">
<l a b e l f o r=" e m a i l ">Email a d d r e s s :</ l a b e l>
<input type=" e m a i l " c l a s s=" form−c o n t r o l " id=" e m a i l ">
</ div>
<div c l a s s=" form−group ">
<l a b e l f o r="pwd">Password :</ l a b e l>
<input type=" password " c l a s s=" form−c o n t r o l " id="pwd">
</ div>
<div c l a s s=" checkbox ">
<l a b e l><input type=" checkbox "> Remember me</ l a b e l>
</ div>
<button type=" submit " c l a s s=" btn ␣ btn−primary ">Submit</button>
</form>
</body>
</html>
Output
20
Chapter 4
About project
21
Figure 4.2: Project Image
22
Chapter 5
Future Scope
The future scope of a sports-related Django web application is quite promising, as there
are numerous directions in which you can expand and enhance the project. Here are some
potential future scope areas for your sports Django web application:
1. Advanced User Profiles: Enhance user profiles to include more detailed information
about players, teams, and their statistics. Allow users to follow their favorite teams
and players, and receive personalized updates and notifications.
2. Live Streaming and Scores: Implement live streaming of sports events and real-
time score updates. Integrate third-party APIs to provide live scores, match commen-
tary, and video highlights.
4. Fantasy Sports: Develop a fantasy sports module where users can create their
own virtual teams, participate in leagues, and earn points based on real-life player
performances.
6. Social Media Integration: Allow users to share their favorite moments, match
updates, and achievements on social media platforms directly from the application.
7. Mobile App Development: Create a mobile app version of the web application to
provide a seamless experience for users on smartphones and tablets.
8. Community Engagement: Add features such as forums, chat rooms, and user-
generated content to foster a sense of community among sports enthusiasts.
9. Virtual Reality (VR) and Augmented Reality (AR): Explore the integration
of VR and AR technologies to provide immersive experiences for users, such as virtual
stadium tours or AR overlays during matches.
23
10. Tournament Management: Develop a comprehensive tournament management
system for organizing and tracking sports events, including fixtures, schedules, regis-
trations, and results.
11. Coach and Player Resources: Provide resources for coaches and players, such as
training videos, tactical insights, and fitness routines.
12. Localization: Expand the application to support multiple languages and cater to a
broader international audience.
14. Data Analytics Dashboard: Create a data analytics dashboard for teams and
coaches to analyze player performance, track trends, and make data-driven decisions.
15. Accessibility and Inclusivity: Ensure the application is accessible to users with
disabilities, conforming to accessibility standards, and providing features for an inclu-
sive user experience.
24
Chapter 6
Conclusion
In conclusion, our Django project has been a significant undertaking that has yielded re-
markable results and invaluable experiences. Throughout the development process, we have
successfully designed and implemented a robust web application that not only meets our
initial goals but also exceeds expectations in terms of functionality, usability, and aesthetics.
One of the notable achievements of our project is the seamless integration of various
Django components. Leveraging Django’s powerful features such as models, views, tem-
plates, and authentication, we were able to create a dynamic and interactive platform that
effectively caters to our users’ needs. The modular nature of Django facilitated efficient code
organization and maintainability, allowing us to focus on implementing unique features and
enhancing the user experience.
Furthermore, our project demonstrates a deep understanding of database management.
By utilizing Django’s Object-Relational Mapping (ORM) capabilities, we established a struc-
tured database schema that efficiently stores and retrieves data. This not only ensures data
integrity but also contributes to the application’s overall performance.
User experience was at the forefront of our design considerations. Through responsive
and user-friendly front-end interfaces, we have provided an intuitive and engaging experience
for our users, regardless of their device or screen size. Incorporating CSS frameworks and
JavaScript libraries enhanced the visual appeal and interactivity of the application, making
it both functional and visually appealing.
Collaboration has been a key pillar of our project’s success. Working as a team, we effec-
tively communicated, shared ideas, and resolved challenges, ensuring a smooth development
process. Regular meetings and version control systems facilitated efficient coordination and
allowed us to stay on track with project milestones.
In retrospect, this Django project has not only allowed us to apply theoretical concepts
learned in our studies but has also given us a deeper insight into real-world web development.
The challenges we encountered along the way have sharpened our problem-solving skills and
encouraged continuous learning. As we conclude this project, we are proud of the end result
and the growth we have experienced as developers.
In the future, we envision expanding the application’s feature set, refining its perfor-
mance, and possibly deploying it to a production environment.
25
List of Figures
26
List of Tables
27
References
[1] https://www.djangoproject.com/
[2] https://www.geeksforgeeks.org/django-tutorial/
[3] https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django
[4] https://www.javatpoint.com/django-tutorial
[5] https://realpython.com/tutorials/django/
[6] https://www.pythontutorial.net/django-tutorial/
[7] https://getbootstrap.com/
28