Django notes
- Django documentation
- Models
from django.db import models
- Templates
- Views
- HttpResponse
from django.http import HttpResponse
- redirect
from django.shortcuts import redirect
- Class-based views
- URL dispatcher
from django.urls import path, re_path
- Forms
from django import forms
- Cache
from django.core.cache import cache
- Management commands
from django.core.management.base import BaseCommand
from django.core.management import call_command
- Run a django-aware script
python manage.py shell < your_script.py
- Middleware
- Queries
- Q objects
from django.db.models import Q
- Settings
from django.conf import settings
- Testing
from django.test import TestCase
- Users
from django.contrib.auth.models import User
Change password
user = User.objects.get(...)
user.set_password("new_password")
user.save() - Executing SQL directly
from django.db import connection
c = connection.cursor()
c.execute(...)
c.close()
Django REST framework
- Serializers
from rest_framework import serializers
- Views
from rest_framework.views import APIView
from rest_framework.decorators import api_view
- Responses
from rest_framework.response import Response
- Status codes
from rest_framework import status
- Testing
from rest_framework.test import APIClient, APITestCase