Basics of Web Development
Basics of Web Development
Web Development:
Web development involves the creation of websites and web applications that run on the Internet. It can be
broken down into two main categories.
o Frontend Development (Client-Side): This focuses on the visual aspects of a website and what
users see and interact with. Technologies used include HTML, CSS, JavaScript, and jQuery.
o Backend Development (Server-Side): This deals with the server side of a website, including
databases, server logic, and APIs. Technologies used include PHP, Ruby, Java, Node.js, Python,
and databases like MySQL, MongoDB, PostgreSQL
Backend vs Frontend:
Framework:
A framework is a set of conceptual structures and guidelines used to build something useful. Frameworks
are software that are developed to build applications. Framework is a collection of tools designed to help
to create your project so you don’t need to start from scratch. A framework may include predefined classes
and functions that can be used to process input, manage hardware devices, and interact with system
architecture. Examples of frameworks are Angular, Laravel, Django, and Spring.
Django is a high-level open-source Python web development framework for building websites. Most
popular Python framework. It follows the model–view–template (MVT) architectural pattern. It was created
by Adrian Holovaty and Simon Willison.
Why Django?
MVT:
The MVT (Model View Template) is a software design pattern. It is a collection of three important
components Model View and Template.
MVT Architecture:
Model: The model is going to act as the interface of your database. It is responsible for maintaining the
database.
View: The View is the user interface. It is the data that a user sees when a user renders a website. It works
as a mediator between the Template and the Model
Template: A template is a file where you describe how the result should be represented. It many consist of
HTML, CSS, and JavaScript.
To see how these components interact, let’s walk through a typical request-response cycle in a Django
application:
1. User Request: A user sends a request to the Django application (e.g., by entering a URL in the
browser).
2. URL Routing: Django’s URL dispatcher maps the URL to a view. This is defined in the urls.py
file, where URL patterns are matched against the incoming request.
3. View Processing: The view function or class is called. This is where the business logic is
executed. The view may query the database using Django models, perform computations, or
interact with other parts of the application.
4. Template Rendering: The view passes data to a template. The template engine processes the
template, replacing placeholders with actual data.
Example:
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
published_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
View: Create a view in views.py to display all posts.
def post_list(request):
posts = Post.objects.all()
<!DOCTYPE html>
<html>
<head>
<title>Blog Posts</title>
</head>
<body>
<h1>Blog Posts</h1>
{% endfor %}
</body>
</html>
o Create a folder
For example: DjangoProjectDemo
You have 18 unapplied migration(s). Your project may not work properly until you apply the
migrations for app(s): admin, auth, contenttypes, sessions.
Starting development server at http://127.0.0.1:8000/ copy this URL and run in browser
o Python
o HTML CSS
o Django
o Django template
o Django snippets
__init__.py: The folder which contains __init__.py file is considered as Python package.
asgi.py: Stands for Asynchronous Server Gateway Interface, used for deploying asynchronous web
applications.
settings.py: The configuration file for your project (database settings, middleware, installed apps, etc.).
URLs.py: The central file where you define URL routes to connect views to specific web addresses.
wsgi.py: Stands for Web Server Gateway Interface, used for deploying WSGI-compatible web applications.
manage.py: A command-line utility to interact with your project. You use it to run the server, make
migrations, create apps, etc.
db.sqlite3: The default database file (SQLite) that Django creates to store your data. You can switch to
other databases like PostgreSQL or MySQL.
If you want to create a subfolder inside your project you can use this command:
Password:
Password (again):