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

Introduction_to_Django_5_fixed

Django 5 beginner tutorial 1

Uploaded by

jdee
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)
24 views

Introduction_to_Django_5_fixed

Django 5 beginner tutorial 1

Uploaded by

jdee
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/ 3

Introduction to Django 5

Introduction to Django 5

What is Django?

Django is a high-level Python web framework that enables developers to build robust, scalable, and secure

web applications quickly. Django emphasizes rapid development and the principle of 'Don't Repeat Yourself'

(DRY), allowing developers to focus on the core functionality of their applications.

Features of Django 5

1. ORM (Object-Relational Mapping): Simplifies database operations by using Python classes instead of raw

SQL.

2. Security: Built-in protections against SQL injection, cross-site scripting (XSS), and cross-site request

forgery (CSRF).

3. Scalability: Suitable for both small projects and large-scale applications like Instagram.

4. Asynchronous Support: Django 5 supports asynchronous views for high-performance applications.

5. Custom Middleware: Easily add or modify request and response processing logic.

6. Admin Interface: Automatically generated admin panel for managing application data.

Installing Django 5

1. Prerequisites:

- Python 3.9 or higher

- pip, Python's package manager

2. Installation Steps:

Page 1
Introduction to Django 5

- Open your terminal or command prompt.

- Create a virtual environment:

python -m venv myenv

source myenv/bin/activate # On Windows, use myenv\Scripts\activate

- Install Django 5:

pip install django

3. Verify Installation:

python -m django --version

Setting Up Your First Django Project

1. Create a new Django project:

django-admin startproject myproject

cd myproject

2. Run the development server:

python manage.py runserver

3. Access the application at http://127.0.0.1:8000/.

Django's MVT Architecture

Django follows the Model-View-Template (MVT) pattern:

- Model: Manages the data and database structure.

- View: Contains the business logic and processes user requests.

Page 2
Introduction to Django 5

- Template: Handles the presentation layer using HTML.

Sample Workflow

1. Create a model:

from django.db import models

class Post(models.Model):

title = models.CharField(max_length=100)

content = models.TextField()

2. Register the model:

from django.contrib import admin

from .models import Post

admin.site.register(Post)

3. Add the model to the database:

python manage.py makemigrations

python manage.py migrate

4. View the data in the Django Admin interface.

Page 3

You might also like