Django
How to Safely Access request from Anywhere in Django
· β˜• 2 min read
In Django, request holds all the information for a single request. Backend processing logic frequently needs information from request. For example, the DRF framework may want to be able to obtain request at any time, or pass some parameters globally. There are third-party Django apps with tools that can satisfy

How to Ensure Concurrent Data Consistency in Django
· β˜• 2 min read
The first part mainly covers optimistic and pessimistic locking. Locking guarantees data consistency under concurrency at the database level. Understanding locks helps you understand concurrency solutions. The second part mainly covers how to guarantee data consistency in concurrent scenarios within Django. 1. About Locks 1.1 Optimistic Locking The starting point

Using utf8mb4 in Django to Support Emoji
· β˜• 3 min read
1. What Is utf8 In theory, utf8 uses 1-6 characters, In practice, the latest utf8 specification uses only one to four bytes, and can encode at most 21 bits, which is exactly enough to represent all 17 Unicode planes. 2. What Is utf8mb4 utf8mb4 is a superset of utf8. In theory, if you were using utf8 before and then change the charset to utf8mb4, it will not cause any problem when reading the existing utf8-encoded data.

Common Commands in Django Development
· β˜• 1 min read
Creating a Django Project 1 django-admin startproject your_project_name Creating an App 1 2 3 django-admin.py startapp your_app_name # ζˆ–θ€… python manage.py startapp your_app_name python manage.py and django-admin do essentially the same thing. The difference is that python manage.py also sets the DJANGO_SETTINGS_MODULE environment variable and adds the project’s path

Django Model and E-R Diagram
· β˜• 6 min read
As requirements are gradually confirmed, the system’s DB model is gradually confirmed as well. Sometimes you use a tool like MySQL Workbench to draw an E-R diagram and then generate MySQL database tables, and at that point you need to reverse-generate Django Models; other times you write the Django Models directly, but then you need to look at the E-R diagram.