0% found this document useful (0 votes)
8 views7 pages

Django Fastapi Cheatsheet

This document serves as a comprehensive cheat sheet for Django and FastAPI developers, outlining essential concepts, commands, and best practices for both frameworks. It covers various topics including project structure, routing, data access, validation, security, caching, API documentation, and deployment strategies. The cheat sheet is organized into sections for each framework, providing quick references for developers to enhance their productivity.

Uploaded by

Mohammed Chr
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)
8 views7 pages

Django Fastapi Cheatsheet

This document serves as a comprehensive cheat sheet for Django and FastAPI developers, outlining essential concepts, commands, and best practices for both frameworks. It covers various topics including project structure, routing, data access, validation, security, caching, API documentation, and deployment strategies. The cheat sheet is organized into sections for each framework, providing quick references for developers to enhance their productivity.

Uploaded by

Mohammed Chr
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

Django & FastAPI Developer Cheat Sheet

Django Cheat Sheet


1. Django Basics
• Project / app (startproject, startapp)

• Structure: [Link], [Link], [Link], [Link]

• MVT architecture (Model View Template)

• [Link] commands

• Reusable apps

• Environment variables

• Static and media files

• Middleware

• Custom management commands

• Signals

• Django Admin

• INSTALLED_APPS configuration

2. Routing & Views


• [Link] routing

• path() / re_path()

• Function-Based Views

• Class-Based Views

• Generic Views
• include()

• URL parameters

• HttpResponse / JsonResponse

• render() / redirect()

• Error handling 404 / 500

3. Data Access
• Django ORM

• [Link]

• Fields: CharField, TextField, DateTimeField, ForeignKey

• Queries: filter(), get(), exclude()

• Relationships: OneToMany, ManyToMany, OneToOne

• select_related() / prefetch_related()

• Aggregations and annotations

• Custom managers
• Raw SQL when needed

• Transactions

4. Architecture
• Service layer modules

• Views / services / repositories separation

• Dependency injection via parameters

• Decoupled apps

• Settings-based configuration

• Optional repository pattern

• Domain services

• Utility modules

5. Validation
• Model validation

• Forms and ModelForms

• clean() / clean_()

• Custom validators

• Required fields and limits

• DRF serializer validation

6. Security
• Django authentication system

• Permissions and groups

• CSRF protection
• XSS protection

• Password hashing

• Secure sessions

• Custom permissions

• SECRET_KEY management

7. Caching
• Django cache framework

• Redis / Memcached backends

• View caching

• Template fragment caching

• Low level caching

8. API Docs
• Django REST Framework
• drf-spectacular / drf-yasg

• OpenAPI / Swagger UI

• Serializer schemas

9. Messaging & Async


• Celery tasks

• Redis / RabbitMQ brokers

• Async workers

• Django Channels WebSockets

10. Templates
• Django template engine

• Template inheritance

• Blocks and includes

• Context processors

• HTMX possible

11. Serialization
• DRF serializers

• ModelSerializer

• Nested serializers

• create() / update() methods

12. Scheduling
• Cron jobs
• Celery Beat

• Scheduled management commands

13. HTTP Clients


• requests

• httpx

• External API integrations

• Timeouts and retries

14. Testing
• Django TestCase

• APIClient (DRF)

• Fixtures

• FactoryBoy

• Mock testing
15. Logging & Monitoring
• Python logging

• Django LOGGING config

• Sentry

• Prometheus / Grafana

16. Deployment
• Gunicorn / Uvicorn

• Nginx

• Docker

• PostgreSQL

• CI/CD

• HTTPS configuration
FastAPI Cheat Sheet
1. FastAPI Basics
• ASGI framework

• Async support

• Type hints

• Auto validation

• Auto docs

• Routers modularization

• [Link] entrypoint

• Depends() system

• Run with Uvicorn

2. REST API
• @[Link]() / post() / put() / delete()

• APIRouter

• Path parameters

• Query parameters

• Body parameters

• Response models

• HTTP status codes

• HTTPException

• Headers and cookies

• File uploads

3. Data Access
• SQLAlchemy

• SQLModel

• Tortoise ORM

• Async SQLAlchemy

• Database sessions

• CRUD operations

• Relationships

• Alembic migrations

4. Dependency Injection
• Depends()

• DB session injection

• Current user injection


• Service injection

• Reusable dependencies

5. Validation
• Pydantic models

• Automatic validation

• Optional / required fields

• Regex / Email / URL types

• Custom validators

6. Security
• OAuth2

• JWT tokens

• OAuth2PasswordBearer

• Role permissions

• passlib password hashing

• CORS middleware

7. Caching
• Redis caching

• Response caching

• TTL strategies

8. API Docs
• Swagger UI auto
• ReDoc auto

• OpenAPI generation

9. Messaging
• BackgroundTasks

• Celery workers

• RabbitMQ / Redis

• Event-driven systems

10. Async Performance


• async def

• await

• Non-blocking I/O

• WebSockets

• Streaming responses
11. Serialization
• Pydantic schemas

• ORM mode

• Computed fields

12. Scheduling
• APScheduler

• Celery Beat

• Cron jobs

13. HTTP Clients


• httpx

• Async external API calls

• Retries and timeouts

14. Testing
• pytest

• TestClient

• AsyncClient

• Dependency overrides

15. Logging
• Python logging

• Request logging middleware


• Prometheus metrics

• OpenTelemetry

16. Deployment
• Uvicorn

• Gunicorn with Uvicorn workers

• Docker

• Nginx

• Kubernetes

• CI/CD pipelines

You might also like