Django Tutorials

Build robust web applications with Django, a high level Python web framework focused on rapid development and clean design. Learn the Django ORM, URLs, views, templates, forms, and the admin. Practice authentication, permissions, security, and performance so your apps are ready for production.

Go deeper with REST APIs using Django REST Framework, async views, caching, Celery for background tasks, and real world deployment. Work with PostgreSQL and other databases, manage settings by environment, and handle static and media files.

Install Django with pip install django. Create a project with django-admin startproject mysite. Change into the folder, run python manage.py migrate, then start the server with python manage.py runserver. Add a feature with python manage.py startapp blog and list blog in INSTALLED_APPS.

Install Django REST Framework with pip install djangorestframework. Add rest_framework to INSTALLED_APPS. Create a serializer for your model, a view or viewset for CRUD, and register routes with a DefaultRouter in urls.py. Return JSON responses and use browsable API for quick testing.

Install a driver with pip install psycopg[binary]. In settings.py set ENGINE to django.db.backends.postgresql and configure NAME, USER, PASSWORD, HOST, and PORT. Run python manage.py migrate and use python manage.py createsuperuser to add an admin user.

Set DEBUG=False, configure ALLOWED_HOSTS, and move secrets to environment variables. Use a process manager and an application server like Gunicorn for WSGI or Uvicorn with Django ASGI. Put Nginx in front, run python manage.py collectstatic, set up HTTPS, and use a real database and cache.

Use the built in test runner with python manage.py test or pytest with pytest-django. Write unit tests for models, views, and forms. Use the test database, factories or fixtures for data, and the Django test client or RequestFactory to simulate requests.