Report of 15 Days Internship
Report of 15 Days Internship
ON
(DJANGO FRAMEWORK)
Submitted by
Student of
Bachelor of Engineering
In
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
Declaration II
Completion Certificate IV
Abstract V
Company Profile VI
1. Introduction of Django 1
- What is Django
- History of Django
4. Django Superuser 6
- Django superuser
VII
WEEK 1 28 JULY 2023 10
5. Django app 11
6. Django models 16
- SQLite database
7. Django Templates 33
VIII
8. Static folders in Django 37
9. Bootstrap 39
- What is bootstrap
10. Dictionary 41
11.Concept of APIs 42
- What is an API?
- Conclusion
IX
1st week
27th July 2023
1. Introduction of Django
What is Django?
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).
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.
Django installation:
3
Django version:
You can check if Django is installed by asking for its version number like this:
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):
4
How to run the project?
To check how the project looks on browser add following command in the
command prompt:
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 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.
6
Django Superuser:
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
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
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.
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
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.
14
app’s model which you add in installed apps whereas migrate executes those SQL
commands in the database file.
So when we run,
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
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
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.
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
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?
There are two ways to start using Bootstrap on your own web site.
You can:
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.
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?
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.
it’s the status code that a server returns if it can’t find the file we requested.
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:
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.
48