Django Web Development Advanced Presentation
Django Web Development 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
• pip install virtualenv
• - Create a Virtual Environment
• virtualenv myenv
• - Activate the Virtual Environment
• - Windows: myenv\Scripts\activate
• - Mac/Linux: source myenv/bin/activate
Creating a Django Project
• - Install Django in Virtual Environment
• pip install django
• - Create a New Django Project
• django-admin startproject myproject
• - Navigate to Project Directory
• cd myproject
• - Project Structure
• - myproject/: Main folder with settings
• - manage.py: Command-line utility
Database Configuration
• - Configure Database in settings.py:
• DATABASES = {
• 'ENGINE': 'django.db.backends.postgresql',
• 'NAME': 'mydatabase',
• 'USER': 'myuser',
• 'PASSWORD': 'mypassword',
• 'HOST': 'localhost',
• 'PORT': '5432',
• }
Creating and Defining Models
• - Create an App
• python manage.py startapp myapp
• - Define a Model in models.py:
• class Product(models.Model):
• name =
models.CharField(max_length=100)
• description = models.TextField()
• price =
models.DecimalField(max_digits=10,
Running Migrations
• - Create Migration Files for Models
• python manage.py makemigrations
• - Apply Migrations to Database
• python manage.py migrate
Rendering Templates
• - Add Templates Directory in settings.py:
• TEMPLATES = [{
• 'DIRS': [BASE_DIR / 'templates'],
• }]
• - Create HTML Template in
templates/home.html:
• <h1>Welcome to Django</h1>
• - Create a View and Render Template
Creating a Superuser
• - Run the Superuser Creation Command
• python manage.py createsuperuser
• - Follow Prompts to Set Up
Running the Django Project
• - Start the Development Server
• 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?