Python
Django Class-Based Views
· ☕ 2 min read
Django has two kinds of views: function-based views and class-based views. The role of a view is mainly to fill in logic and return a response body. Function-based views are hard to extend and have a low rate of code reuse. Class-based views, on the other hand, can use inheritance

Permission Management in Django REST Framework
· ☕ 3 min read
1. Permission Management in DRF Permission management in Django REST Framework consists of two parts. One is Authentication. It specifies how the user is authenticated, obtaining request.user. The other is Permissions. It performs permission control over Django resources and user categories. 1.1 Authentication Methods The relevant source is in the rest_framework/authentication.

Django Template Inheritance
· ☕ 2 min read
1. The Scenario In a project, elements such as the header and footer are often reused. To avoid rewriting these elements on every page, and so that a change does not require editing each page individually, the common parts need to be extracted — that is Django template inheritance. 2.

Django Decorators
· ☕ 2 min read
When developing with a separated front end and back end, some of the API endpoints provided to the front end use GET requests and some use POST requests. To keep the back end from throwing an error while reading values from request in views.py, you had to check the request

Django Snippets
· ☕ 3 min read
1. Auto-Register All Models in Admin admin.py 1 2 3 4 5 6 7 8 9 10 # -*- coding: utf-8 -*- import inspect from django.contrib import admin from . import models for name, obj in inspect.getmembers(models): try: if inspect.isclass(obj): admin.site.register(getattr(models, name)) except Exception as e: pass 2. Get All View Names Get all view names of the project