Django Web Development Formatted Advanced Presentation
Django Web Development Formatted Advanced Presentation
Advanced Guide
Setting Up, Building, and Running
Your Django Project
Your Name, Date, Contact
Information
Agenda
• - Environment Setup and Virtual Environment
• - Creating a Django Project
• - Database Configuration and Connection
• - Models and Migrations
• - Templates and Rendering
• - Creating a Superuser
• - Running the Project
• - Code Examples and Terminal Screenshots
• - Q&A
Environment Setup
• - Install Python
• - Install Virtual Environment:
• ```bash
• pip install virtualenv
• ```
• - Create a Virtual Environment:
• ```bash
• virtualenv myenv
• ```
Creating a Django Project
• - Install Django in Virtual Environment:
• ```bash
• pip install django
• ```
• - Create a New Django Project:
• ```bash
• django-admin startproject myproject
• ```
• - Navigate to Project Directory:
Database Configuration
• - Configure Database in settings.py:
• ```python
• DATABASES = {
• 'default': {
• 'ENGINE':
'django.db.backends.postgresql',
• 'NAME': 'mydatabase',
• 'USER': 'myuser',
• 'PASSWORD': 'mypassword',
Creating and Defining Models
• - Create an App:
• ```bash
• python manage.py startapp myapp
• ```
• - Define a Model in models.py:
• ```python
• from django.db import models
• class Product(models.Model):
Running Migrations
• - Create Migration Files for Models:
• ```bash
• python manage.py makemigrations
• ```
• - Apply Migrations to Database:
• ```bash
• python manage.py migrate
• ```
Rendering Templates
• - Add Templates Directory in settings.py:
• ```python
• TEMPLATES = [
• {
• 'BACKEND':
'django.template.backends.django.DjangoTem
plates',
• 'DIRS': [BASE_DIR / 'templates'],
• ...
Creating a Superuser
• - Run the Superuser Creation Command:
• ```bash
• python manage.py createsuperuser
• ```
• - Follow Prompts to Set Up
Running the Django Project
• - Start the Development Server:
• ```bash
• python manage.py runserver
• ```
• - Access the App at http://127.0.0.1:8000/
Advanced Tips and Tools
• - Admin Customization
• - Django REST Framework for APIs
• - Testing with pytest
Q&A
• Questions?