Jul 23, 2024
python3.10 -m venv venv, source venv/bin/activate (Mac/Linux), venv\Scripts\activate (Windows)mkdir -p ~/dev/drf, cd ~/dev/drfrequirements.txt includes Django, DRF, PyYAML, Python Requests, Django CORS Headersdjango-admin startproject cfehome ., python manage.py runserver 8000http://httpbin.org/anythingpython manage.py startapp api, add api to INSTALLED_APPS in settings.pyapi/urls.py and include in main urls.pyJsonResponse to return data in viewsmodel_to_dict and DRF's serializers@property methods for dynamic dataInstall DRF: Add rest_framework to INSTALLED_APPS
API Views: Use DRF's APIView and Response classes; handle methods (GET, POST)
Generic Views: Shorten code using ListCreateAPIView, RetrieveUpdateDestroyAPIView
Permissions and Authentication
IsAuthenticated, IsAdminUser)pip install django-cors-headers, add to INSTALLED_APPS and middlewareCORS_ALLOWED_ORIGINS or use regex in CORS_URLS_REGEX