Download as pdf or txt
Download as pdf or txt
You are on page 1of 57

AN INTERNSHIP REPORT

ON

WEB DEVELOPMENT USING PYTHON

(DJANGO FRAMEWORK)

Submitted by

Vaza Sharmin Abdulkadir (200140111005)

Student of

Bachelor of Engineering
In

ELECTRONICS & COMMUNICATION ENGINEERING

GOVERNMENT ENGINEERING COLLEGE, BHARUCH

I
DECLARATION

I do hereby solemnly declare that the work presented in this Internship Report has
been carried out by me and has not been previously submitted to any other
University, College, and Organization for any academic Qualification and
Certificate.

I hereby warrant that the work I have presented does not breach any existing
copyright acts.

Student Name:
Vaza Sharmin Abdulkadir

II
CONFIRMATION LETTER

III
CERTIFICATE OF COMPLETION

IV
ABSTRACT

Python is very famous because of its wide area of applications. One of the
applications of python is web development. Many frameworks of python are
available for web development for example Django, Flask, Web2py, CherryPy etc.
Django is very popular framework and huge acceptance in corporate industry. In this
internship we will going to develop website along with real time API handling. This
web page will fetch live data and display in well-structured and responsive manner.

V
COMPANY PROFILE

Established in 2016, incorporation with our parent IT company, INFOLABZ IT SERVICES PVT.
LTD. has managed to make it's own position in IT Sector. We are involved in Web Development,
App Development, Progressive Web Application Development, IOT solutions, Graphics &
Designing, Digital Marketing, Domain & Hosting services, SMS services etc.

In the span of seven years, we have managed to deliver all projects on time with utmost accuracy
to our clients across the globe. We have dedicated teams of experienced and hardworking
developers. Our developers who are always willing to take new challenges and looking forward to
learn new things, are heart of this company.

Our objective is to sustain with exponential growth in IT industry. Our mission is to deliver the
best with top notch quality every quarter and vision is to develop a product with one of its kind
concepts which could be used by millions of people.

VI
TABLE OF CONTENT

WEEK / DAY NO CONTENT PAGE NO

Declaration II

Confirmation Letter III

Completion Certificate IV

Abstract V

Company Profile VI

WEEK 1 27JULY 2023 1

1. Introduction of Django 1

- What is Django

- History of Django

2. Django Environment Setup 2

3. Django Project Creation 4

- How to create Django project?

- How to run the project?

4. Django Superuser 6

- Django Admin Interface

- Django superuser

VII
WEEK 1 28 JULY 2023 10

- Superuser permission configurations

5. Django app 11

- What is an app in Django

- How to make app?

6. Django models 16

- What is model in Django?

- SQLite database

WEEK 1 31 JULY 2023 18

- Multiple Database Tables with different Fields

WEEK 1 01 AUGUST 2023 21

- concept of foreign key and primary key

WEEK 1 02 AUGUST 2023 23

- Assignment project task

- Admin Panel Project : Backend Bank Customer DB


development

WEEK 2 03 AUGUST 2023 33

7. Django Templates 33

- HTML page in Django

- Routing of HTML pages

WEEK 2 04 AUGUST 2023 37

VIII
8. Static folders in Django 37

9. Bootstrap 39

- What is bootstrap

WEEK 2 07 AUGUST 2023 41

10. Dictionary 41

11.Concept of APIs 42

- What is an API?

- Making API Requests in Python

- API request example

WEEK 2 08 AUGUST 2023 45

- API Integration in Webpages using Django Framework

WEEK 2 09 AUGUST 2023 45

- Assignment project task

- Project: Real time news website using inshorts API

WEEK 2 10 AUGUST 2023 48

- Conclusion

IX
1st week
27th July 2023

1. Introduction of Django
What is Django?

Django is a high-level, open-source web framework written in Python that enables


developers to build web applications quickly and efficiently. It follows the Model-
View-Controller (MVC) architectural pattern, although it's often referred to as
Model-View-Template (MVT) in Django's context. The framework provides
various tools, libraries, and built-in features to simplify and streamline common
web development tasks.

Django follows the "batteries included" philosophy, meaning it provides a wide


range of built-in tools and features to make development efficient and consistent.
This philosophy encourages developers to focus on their application's unique
features rather than reinventing the wheel for common tasks.

Overall, Django has gained popularity due to its robustness, scalability, and active
community support. It's widely used in the development of various types of web
applications, from content management systems and e-commerce platforms to
social networking sites and more.

History of Django:

Django was developed between 2003 and 2005 by a web team who were
responsible for creating and maintaining newspaper websites. After creating
several sites, the team began to factor out and reuse lots of common code and
design patterns. This common code evolved into a generic web development
framework, which was open sourced as the "Django" project in July 2005.
Django has continued to grow and improve, from its first milestone release (1.0) in
September 2008 through to the recently released version 4.0 (2022). Each release
has added new functionality and bug fixes, ranging from support for new types of

1
databases, template engines, and caching, through to the addition of "generic" view
functions and classes (which reduce the amount of code that developers have to
write for a number of programming tasks).

2. Django Environment Setup

Setting up a Django environment involves installing the necessary tools and


dependencies to start building web applications using the Django framework.

To install Django, you must have Python installed, and a package manager
like PIP.

Python:
To check if your system has Python installed, run this command in the command
prompt:

2
If Python is installed, you will get a result with the version number, like this:

PIP:

To check if your system has PIP installed, run this command in the command
prompt:

If PIP is installed, you will get a result with the version number.

For me, on a windows machine, the result looks like this:

Django installation:

Django is installed using pip with the following command:

Which will give result that looks like this:

3
Django version:

You can check if Django is installed by asking for its version number like this:

3. Django project creation

How to create Django project:

Once Django is installed, you can create a new Django project. Project can be
created by following command (project name can be anything here the project
name is infolabz):

Django creates a infolabz folder on my computer, with this content:

4
How to run the project?

To check how the project looks on browser add following command in the
command prompt:

The result of this command will be:

By clicking on the link http://127.0.0.1:8000/, the project will open in the browser
and result will be as shown below:

5
If the server is still running, and you are not able to write commands, press
[CTRL] +[C] to stop the server and you should be back in the virtual environment.

4. Django Superuser

Django Admin Interface:

Django provides a default admin interface which can be used to perform create,
read, update and delete (CRUD) operations on the model directly. It reads set of
data that explain and gives information about data from the model, to provide an
instant interface where the user can adjust contents of the application. This is an in-
built module and design to execute admin related work to the user.

The admin app(django.contrib.admin) is enabled by default and already added into


the INSTALLED_APPS list present in the settings.py file.

To access this admin interface on browser write ‘/admin/’ at


‘localhost:8000/admin/’ and it shows the output as given below:

6
Django Superuser:

To be able to log into the admin application, we need to create a user.

This is done by typing this command in the command view:

To create a superuser you must enter username, e-mail address (you can just pick a
fake e-mail address), and password:

7
Now start the server again and type 127.0.0.1:8000/admin/ in the address bar.fill
in the form with the correct username and password:

Result of this should be as below Here you can create, read, update, and delete
groups and users. In Django, the "superuser" refers to a user account with special
administrative privileges that allow them to access and manage various aspects of a
Django web application, including the admin interface, database records, and
more. Superusers have the highest level of control over the application.

8
9
1st week
28th July

Superuser permission configurations:

By default, the superuser has full access to all models and their records. You can
further customize the permissions of the superuser or other users through the
Django admin interface or by defining custom permission levels in your models.
while superusers have the ability to perform powerful actions within the
application, it's important to exercise caution when granting superuser status and to
adhere to the principle of least privilege. Not all users should have superuser
permissions, as this level of access can potentially lead to unintended data loss or
security issues.

When you click on ‘users’ in admin interface following page comes up in that
permissions section you can change permissions according to our need:

10
You can further add or remove user permissions according to the need.
click on save to save the changes in the permissions.

5. Django app

What is an app in Django?

In Django, an "app" refers to a modular component that encapsulates a specific


functionality or set of related functionalities within a larger web application. Apps
are a way of organizing code and separating different aspects of your project into
manageable and reusable units. They help maintain a clean and structured
codebase, making it easier to develop, test, and maintain your Django project.

11
Basically, an app is a web application that has a specific meaning in your project,
like a home page, a contact form, or a members database.

How to make app?

App can be created by following command in terminal:

Each Django app typically includes the following components:

Once you've created an app, you can include it in your project's settings by adding
the app's name to the INSTALLED_APPS setting. This allows Django to
recognize and use the app's components in your project. Django apps promote
modularity and reusability, making it easier to manage complex projects and
collaborate with other developers. They help you break down your application's
functionality into smaller, manageable pieces, and allow for easier maintenance
and expansion in the future.

12
6. Django models

What is model in Django?

A Django model is the built-in feature that Django uses to create tables, their
fields, and various constraints. In short, Django Models is the SQL of Database
one uses with Django. SQL (Structured Query Language) is complex and
involves a lot of different queries for creating, deleting, updating or any other
stuff related to database. Django models simplify the tasks and organize tables
into models. Generally, each model maps to a single database table. we can use
admin panel of Django to create, update, delete or retrieve fields of a model and
various similar operation. Django models provide simplicity, consistency, version
control and advanced metadata handling.
• Each model is a Python class that subclasses django.db.models.Model.
• Each attribute of the model represents a database field.

13
Create Model(table):

To create a model, navigate to the models.py file in the newapp folder. Open it
and add a table by creating a class, and describe the table fields in it:

Example: here we added contactus and userinfo table by creating class for both of
them.in contactus table the table fields are name, email, phone and message in
same way table fields for userinfo are created.

Migrations and makemigration:

Whenever we create a Model, Delete a Model, or update anything in any of


models.py of our project. We need to run two commands makemigrations and
migrate. makemigrations basically generates the SQL commands for preinstalled
apps (which can be viewed in installed apps in settings.py) and your newly created

14
app’s model which you add in installed apps whereas migrate executes those SQL
commands in the database file.

So when we run,

Render a model in Django Admin Interface:

To render a model in Django admin, we need to modify app/admin.py. Go to


admin.py in newapp and enter the following code. Import the corresponding model
from models.py and register it to the admin interface.

This code imports the admin module from the django.contrib package and the
Model class from the models module in the current directory. It then registers the
Model class with the Django admin site, which allows the model to be managed
through the Django admin interface. This means you can perform CRUD(Create,
Read, Update, Delete) operations on the Model using the Django admin interface.
This code does not produce any output, it simply registers the Model with the
admin site, so that it can be managed via the Django admin interface.

15
Now we can check whether the model has been rendered in Django Admin.
Django Admin Interface can be used to graphically implement CRUD (Create,
Retrieve, Update, Delete).

SQLite Database:

When we created our first app and started the server, a new file named ‘db.sqlite3′
is created in project directory. The file is a database file that will keep all of the
data that you will be generating. Since Django is a server-side framework, it treats
computer as the host when you run the server from the command line or terminal.
This file is generated automatically since Django’s database is set to SQLite by
default, which is good for testing and has a lot of functionality, but if you want
your website to be scalable, you can convert it to a more efficient database. here all
of the backend code is written in Python, which is a Django Model advantage.

Here are the steps to integrate the Django project with MySQL:

16
Install DB Browser: DB Browser for SQLite is an open-source, high-quality
visual tool for creating, developing, and modifying SQLite-compatible database
files. Users and developers who want to create, search, construct, and edit
databases will find it useful. It’s a tool that’s used by both developers and end-
users, therefore it needs to be as simple as possible. Depending on your operating
system, download SQLite standard installation.

Now you may access the SQLite database and see it from the database list. The
following tables are there in the database.

17
1st week
31st July

Multiple Database Tables with different Fields:

The most important part of a model and the only required part of a model is the
list of database fields it defines. Fields are specified by class attributes. Here is a
list of all Field types used in Django.

18
19
On this day we learned to make multiple database table with different fields.

20
1st week
1st August

Concept of foreign key and primary key:

In Django, both Foreign Key (FK) and Primary Key (PK) are concepts related to
database relationships and data integrity.

Primary Key (PK): A Primary Key is a unique identifier for each record in a
database table. In Django models, each model class is automatically assigned a
primary key field named "id" by default, unless you specify otherwise. You can
also explicitly define your own primary key field using the ‘primary_key=True’
parameter in a model's field definition.

Foreign Key (FK): A Foreign Key is a field in a database table that is used to
establish a link between two tables. It creates a relationship between records in one
table to records in another table. In Django, a Foreign Key field is used to create
this relationship between models. The ‘on_delete’ parameter specifies the
behaviour when the referenced record is deleted.

21
Django's Foreign Key and Primary Key concepts help you design structured and
normalized databases, ensuring data integrity and efficient querying while allowing
you to establish meaningful relationships between different data entities.

22
1st week
2nd August

ASSGNMENT 1

23
Codes of the assignment:

Settings.py:

24
models.py :

25
26
admin.py :

27
Result of assignment:

28
29
30
31
Database in SQL Lite:

32
2nd week
3rd August

7. Django Templates

Django templates are a fundamental part of the Django web framework, which is a
high-level Python framework for building web applications quickly and efficiently.
Django templates provide a way to generate dynamic HTML content by
embedding Python code within HTML markup. They separate the presentation
logic from the actual application logic, promoting a clean separation of concerns in
your web application.

HTML Page in Django:

First, we need to create a templates folder inside the older, app folder and create
HTML files in the templates folder.

Now write the HTML code in the HTML files. here is an example of an index.html
file.

33
Now following codes are written in views.py , urls.py of app folder and urls.py of
project folder. after that in terminal migrate command and runserver command
are executed.

34
Output:

35
Routing of html pages:

Following code can be added in a html page to link it with other html page:

This will create a hyperlink in the web page and routing of different html pages can
be done.

36
2nd week
4th August

8. Static folders in Django

In Django, static folders play a crucial role in managing and serving static files,
such as CSS, JavaScript, images for the web application. These files are typically
the ones that do not change dynamically per user request and are shared across all
users.

Create a directory named static within your Django app's main directory. Inside
the static directory, you can organize your static files into subdirectories based on
their purpose, like css, js, images, etc. now add codes in the static files according
to the need.

Next we need to add the static files into the html page. Write following code to do
that:

37
38
9. Bootstrap
What is bootstrap?

Bootstrap is an open-source front-end framework used for building responsive and


visually appealing websites and web applications. It was originally created by
Twitter and now it is maintained as an open-source project with a large
community of developers contributing to its development.

The main purpose of Bootstrap is to provide developers with a set of pre-designed


HTML, CSS, and JavaScript components and utilities that can be easily integrated
into web projects. This framework helps streamline the web development process
by offering standardized design elements and responsive layouts that adapt well to
various screen sizes, making it suitable for both desktop and mobile devices.

Bootstrap 5 is the newest version of Bootstrap; with new components, faster


stylesheets, more responsiveness etc. It supports the latest, stable releases of all
major browsers and platforms. The main differences between Bootstrap 5 and
Bootstrap 3 & 4, is that Bootstrap 5 has switched to JavaScript instead
of jQuery.

There are two ways to start using Bootstrap on your own web site.

You can:

• Download Bootstrap from getbootstrap.com


• Include Bootstrap from a CDN

The following example shows the code for a basic Bootstrap page here we have
added table bootstrap in a html file.

39
Output:

40
2nd week
7th August

10. Dictionary

A dictionary in Python is a built-in data structure that allows you to store and
organize data in key-value pairs. Each key in a dictionary must be unique, and it
maps to a corresponding value. Dictionaries are also sometimes referred to as
associative arrays or hash maps in other programming languages. Dictionaries are
denoted by curly braces {} and consist of key-value pairs separated by colons.

Here's a basic example of a dictionary in Python:

In the above example, "name", "age", and "city" are keys, and "John", 30, and
"New York" are their corresponding values. Dictionaries are quite versatile and
can store various types of values as their elements, including numbers, strings,
lists, other dictionaries, or even functions.

41
11. Concept of APIs

What is an API?

Application Programming Interface (API) is a software interface that allows two


applications to interact with each other without any user intervention. API is a
collection of software functions and procedures. In simple terms, API means a
software code that can be accessed or executed. API is defined as a code that helps
two different software’s to communicate and exchange data with each other.
It offers products or services to communicate with other products and services
without having to know how they’re implemented.

Making API Requests in Python:

In order to work with APIs in Python, we need tools that will make those requests.
In Python, the most common library for making requests and working with APIs is
the requests library. The requests library isn’t part of the standard Python library,
so you’ll need to install it to get started.

If you use pip to manage your Python packages, you can install requests using the
following command:

42
After that we need to import the requests:

There are many different types of requests. The most commonly used one,
a GET request, is used to retrieve data. Because we’ll just be working with
retrieving data, our focus will be on making ‘get’ requests.
When we make a request, the response from the API comes with a response
code which tells us whether our request was successful. Response codes are
important because they immediately tell us if something went wrong.

To make a ‘GET’ request, we’ll use the requests.get() function, which requires
one argument — the URL we want to make the request to. We’ll start by making a
request to an API endpoint that doesn’t exist, so we can see what that response
code looks like.

The get() function returns a response object. We can use


the response.status_code attribute to receive the status code for our request:

it’s the status code that a server returns if it can’t find the file we requested.

API request example:

Requesting data from free bitcoin API. Importing requests in python folder named
bitcoin.py and result of code:

43
44
2nd week
8th August and 9th August:

API Integration in Webpages using Django Framework

Assignment 2:

45
Codes :

46
Output:

47
2nd week
10th August

Conclusion
Django is a rapid web development framework and if you want to get your
application built fast within a few days, there is no better framework than
Django Web Framework. Django gives all the features included, also called
“Batteries Included Framework”. It has a built-in admin interface which
makes it easy to work with it. Django is a high-level python-based web
framework which allows you to quickly create web applications without all
of the installation or dependency problems that you normally will find with
other frameworks. For developing a Web Application or API Backend.

For Rapid Development of some web application, Deploying the application


Fast and Scaling it according to your needs, A Perfect ORM for working
with databases instead of database queries, To develop a secure single-
page application for either retrieving data or posting data.

48

You might also like