0% found this document useful (0 votes)
56 views

Django Report

This document provides a summary of the internship project completed by Kanchan Kumari at MBM University. The project focused on developing a web application using the Django framework to showcase its capabilities for building dynamic and scalable websites. The web application, called DjangoShop, simulates an online e-commerce platform with features like user authentication, product catalog, shopping cart, orders, and user profiles. Through implementing DjangoShop, key aspects of Django's functionality are explored, including routing, database management, forms, and authentication. Overall, the project demonstrates how Django can be used to create sophisticated and feature-rich web applications in a maintainable and user-centered way.

Uploaded by

Padam Kishor
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)
56 views

Django Report

This document provides a summary of the internship project completed by Kanchan Kumari at MBM University. The project focused on developing a web application using the Django framework to showcase its capabilities for building dynamic and scalable websites. The web application, called DjangoShop, simulates an online e-commerce platform with features like user authentication, product catalog, shopping cart, orders, and user profiles. Through implementing DjangoShop, key aspects of Django's functionality are explored, including routing, database management, forms, and authentication. Overall, the project demonstrates how Django can be used to create sophisticated and feature-rich web applications in a maintainable and user-centered way.

Uploaded by

Padam Kishor
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/ 33

A

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

This is to certify that the “Internship report” submitted by KANCHAN KUMARI


(Roll. No.: 22UBAML4104) is work done by his and submitted during 2022-2023
academic year, in partial fulfillment of the requirements for the award of the degree of
BACHELOR OF TECHNOLOGY in COMPUTER SCIENCE AND ENGINEERING, at
MBM University, Jodhpur.

Counter Signed by:


Ms. Divya Khatri
Branch coordinator
Dept.: Computer Science and Engineering(AI&ML)
MBM University,
Jodhpur (Raj.)
Date:

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 am extremely great full to Engineering College Barmer , department of CSE ,


and friends who helped me in successful completion of this internship.

I would like to thank Our faculty Mr. Deepak Van for his constructive criticism
throughout my internship.

I am extremely great full to MBM University , Department staff of MBM Uni-


versity , and friends who helped me in the successful completion of this internship.

Grateful to:

• MBM University, Jodhpur.

• Engineering College Barmer, Department of CSE (AI ML).

• 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

2 Static Files Handling 8


2.0.1 Project Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.0.2 Settings Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.0.3 Collecting Static Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.0.4 Serving Static Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.0.5 Deploying to Production . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.0.6 Using Static Files in Templates . . . . . . . . . . . . . . . . . . . . . . 9
2.1 Django Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Django Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.1 Instantiate the form . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.2 Django Database Connectivity . . . . . . . . . . . . . . . . . . . . . . 12
2.2.3 Database Migrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Django Database Migrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.1 makemigrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.2 migrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.3 sqlmigrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.4 showmigrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3 Django Request and Response 16


3.1 Django HttpRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Django HttpRequest Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Download the Bootstrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 Create a Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

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.

Figure 1.1: Model View Template

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.

1.1 Django Admin Interface


Django provides a built-in admin module which can be used to perform CRUD operations
on the models. It reads metadata from the model to provide a quick interface where the
user can manage the content of the application.
This is a built-in module and designed to perform admin related tasks to the user.
Let’s see how to activate and use Django’s admin module (interface).
The admin app (django.contrib.admin) is enabled by default and already added into
INSTALLED_APPS section of the settings file.
To access it at browser use ’/admin/’ at a local machine like localhost:8000/admin/ and it
shows the following output:

1.1.1 Create an Admin User


In Django, the python manage.py createsuperuser command is used to create a superuser
account in your Django application’s database. A superuser is a user account with elevated
privileges, allowing them to access the Django admin interface and perform administrative
tasks.
Once the superuser is created, you can use their credentials to log in to the Django admin

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.

1.2 Django App


In the previous topics, we have seen a procedure to create a Django project. Now, in this
topic, we will create app inside the created project.
Django application consists of project and app, it also generates an automatic base directory
for the app, so we can focus on writing code (business logic) rather than creating app
directories.
The difference between a project and app is, a project is a collection of configuration files
and apps whereas the app is a web application which is written to perform business logic.

1.2.1 Creating an App


The python manage.py startapp command in Django is used to create a new Django ap-
plication within your project. An application is a modular component that encapsulates a
specific functionality or set of features within your overall Django project.
In your case, it seems like you want to create an application named "members." Here’s how
you would use the startapp command to create this new application: To create a new Django
application named "members," follow these steps:
To create a new Django application named "members," follow these steps:

1. Open your terminal or command prompt.

2. Navigate to the root directory of your Django project (the directory containing the
manage.py file).

3. Run the following command:

python manage.py startapp members

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:

• models.py: Define database models for the application.


• views.py: Define views and request handlers for the application.
• urls.py: Define URL patterns specific to the application.
• admin.py: Configure how the application’s models are displayed in the admin
interface.
• Other necessary files and directories for templates, static files, etc.

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

from django . c o n t r i b import admin


from django . u r l s import path

urlpatterns = [
path ( ’ admin/ ’ , admin . s i t e . u r l s ) ,
]

6
1.2.2 Django URL Functions

Name Description Example


path(route, It returns an element for inclusion path(’index/’,
view, in urlpatterns. views.index,
kwargs=None, name=’main-view’)
name=None)
re_path(route, It returns an element for inclusion re_path(r’^index/$’,
view, in urlpatterns. views.index,
kwargs=None, name=’index’)
name=None)
include(module, It is a function that takes a full
namespace=None) Python import path to another
URLconf module that should be
"included" in this place.
It is used for registering a con-
register_converter(converter,
type_name) verter for use in path() routes.

Table 1.1: Table Django URL Functions.

7
Chapter 2

Static Files Handling

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:

2.0.1 Project Structure


In a typical Django project, you’ll find a directory named static at the top level. This
directory is where you should place all your static files. Within the static directory, you
can organize your files into subdirectories, such as css, js, images, etc., to maintain a clear
structure.

2.0.2 Settings Configuration


In your Django project’s settings.py file, you’ll find a setting called STATIC_URL. This
setting specifies the base URL where Django will look for static files. By default, it is set to
/static/.

2.0.3 Collecting Static Files


During the development phase, Django’s collectstatic management command is used to
collect all your static files from various locations and copy them into a single directory. This
directory is determined by the STATIC_ROOT setting in your settings.py file. It’s a good
practice to create a folder called staticfiles at the project level to serve these files during
development.

2.0.4 Serving Static Files


During development, Django’s built-in development server (runserver) automatically serves
static files from the staticfiles directory. This allows you to work with your static files
without any additional configuration.

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.

2.0.6 Using Static Files in Templates


In your HTML templates, you can use the {% static %} template tag to generate URLs for
your static files. This ensures that the correct URL is used, whether you’re in development
or production.
Example usage:
<l i n k r e l=" s t y l e s h e e t " href="{%␣ s t a t i c ␣ ’ c s s / s t y l e s . c s s ’ ␣%}">
<s c r i p t src="{%␣ s t a t i c ␣ ’ j s / s c r i p t . j s ’ ␣%}"> </ s c r i p t>
<img src="{%␣ s t a t i c ␣ ’ images / l o g o . png ’ ␣%}" a l t=" Logo ">

2.1 Django Forms


Django Forms are a crucial component of the Django web framework, designed to simplify
the process of creating and handling HTML forms. Forms are used to collect and validate
user input, such as data entry, user registration, search queries, and more, and then process
that data on the server side.
Here’s an overview of Django Forms and their main features:
1. Form Class Definition: In Django, you define forms using Python classes that
inherit from django.forms.Form or its subclasses. Each form class corresponds to a
specific form in your application.
2. Fields: A form class consists of various fields, which represent the input elements
in the HTML form. Django provides a wide range of field types, such as CharField,
IntegerField, EmailField, DateField, ChoiceField, BooleanField, and many more.
3. Widgets: Fields in Django Forms are associated with widgets, which determine how
the form field is rendered as HTML. Widgets control the appearance and behavior of
the input element on the web page.
4. Validation: Django Forms include built-in validation for submitted data. You can
specify validation rules for each form field, ensuring that the user-provided data meets
certain criteria before it is processed.
5. Rendering Forms: Django Forms provide methods for rendering the form as HTML.
These methods allow you to easily generate the necessary HTML code to display the
form on a web page. You can customize the form’s appearance using HTML attributes
or by creating custom templates.
6. Handling Form Submission: When a user submits a form, Django processes the
submitted data, validates it based on the form’s defined rules, and then provides the
validated data as a dictionary-like object. You can access this data in your view
functions to perform further actions, such as saving it to a database.

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.

2.2 Django Form Validation


Django provides comprehensive built-in form validation to ensure that the data submitted
through forms meets specific criteria before it is processed. Here’s an overview of how Django
handles form validation:

// models.py
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 "
Now, create a form which contains the below code.
// forms.py

from django import forms


from myapp . models import Employee

c l a s s EmployeeForm ( forms . ModelForm ) :


c l a s s Meta :
model = Employee
f i e l d s = "__all__"

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.

< !DOCTYPE html>


<html lang=" en ">
<head>
<meta charset="UTF−8">
<t i t l e>Index</ t i t l e>
</head>
<body>
<form method="POST" c l a s s=" post−form "
e n c t y p e=" m u l t i p a r t / form−data ">
{% c s r f _ t o k e n %}
{{ form . as_p }}
<button type=" submit " c l a s s=" s a v e ␣ btn ␣ btn−d e f a u l t ">
Save</button>
</form>
</body>
</html>

11
Start server and access the form.

Figure 2.1: access the form

2.2.2 Django Database Connectivity


Django is a high-level Python web framework that includes built-in support for working
with databases. It provides an Object-Relational Mapping (ORM) system that abstracts
away many of the complexities of database management and allows you to interact with
databases using Python code instead of writing raw SQL queries. Here are the basic steps
and concepts related to Django’s database connectivity and usage:

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 ’ )

5. Creating, Updating, and Deleting Records:


You can use model instances to create, update, and delete records in the database.

new_employee = Employee ( f i r s t _ n a m e =’John ’ ,

last_name =’Doe ’ , e m a i l =’ john@example . com ’ )


new_employee . s a v e ( )

employee = Employee . o b j e c t s . g e t ( pk=1)


employee . e m a i l = ’ newemail@example . com ’
employee . s a v e ( )

employee . d e l e t e ( )

6. Performing Aggregations and Annotations:


Django provides methods to perform aggregations (e.g., counting, summing) and an-
notations (adding calculated fields) on querysets.
from django . db . models import Count

num_employees = Employee . o b j e c t s . count ( )

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 ’ ) )

7. Raw SQL Queries:


While Django encourages the use of its ORM, you can also execute raw SQL queries
if needed.

from django . db import c o n n e c t i o n

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 :

c u r s o r . e x e c u t e ( "SELECT ∗ FROM myapp_employee WHERE last_name =

%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.2.3 Database Migrations


Migration is a way of applying changes that we have made to a model, into the database
schema. Django creates a migration file inside the migration folder for each model to create
the table schema, and each table is mapped to the model of which migration is created.
Django provides the various commands that are used to perform migration related tasks.
After creating a model, we can use these commands.

2.3 Django Database Migrations


In Django, database migrations are a way to manage changes to your application’s models
and their corresponding database schema. Here are some commonly used commands related
to database migrations:

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

from django . db import m i g r a t i o n s , models


c l a s s Migration ( migrations . Migration ) :
i n i t i a l = True
dependencies = [
]
operations = [
m i g r a t i o n s . CreateModel (
name=’Employee ’ ,
f i e l d s =[
( ’ id ’ , models . Au toFiel d ( a u t o _ c r e a t e d=True ,

primary_key=True , s e r i a l i z e =F a l s e , verbose_name =’ID ’ ) ) ,


( ’ 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)) ,
],
o p t i o n s ={
’ db_table ’ : ’ employee ’ ,
},
),
]

15
Chapter 3

Django Request and Response

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.

3.1 Django HttpRequest

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.

Table 3.1: Django HttpRequest Attributes.

3.2 Django HttpRequest Methods

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.

Table 3.2: HttpRequest Methods.

3.3 Download the Bootstrap


Visit the official site https://getbootstrap.com to download the bootstrap at local machine.
It is a zip file, extract it and see it contains the two folder.

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.

3.4 Create a Directory


Create a directory with the name static inside the created app and place the css and jss
folders inside it. These folders contain numerous files, see the screen shot.

Figure 3.2: Bootstrap folder.

See the index.html file.

< !DOCTYPE html>

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

Figure 3.3: Output html.file.

20
Chapter 4

About project

Figure 4.1: Project Image

21
Figure 4.2: Project Image

Figure 4.3: 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.

3. E-Commerce Integration: Add an e-commerce section to sell sports merchandise,


tickets, and memorabilia related to the teams and players featured on the platform.

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.

5. Predictive Analytics: Implement predictive analytics to forecast match outcomes,


player performance, and team rankings using historical data and machine learning
algorithms.

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.

13. Sponsorship and Advertising: Integrate sponsorship and advertising opportunities


to generate revenue through partnerships with sports-related brands.

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

1.1 Model View Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3


1.2 createsuperuser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1 access the form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1 Bootstrap folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19


3.2 Bootstrap folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Output html.file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.1 Project Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21


4.2 Project Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3 Project Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

26
List of Tables

1.1 Table Django URL Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.1 Django HttpRequest Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . 17


3.2 HttpRequest Methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

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

You might also like