• Django’s select_related and prefetch_related functions to optimize QuerySet queries


    When the database has foreign keys, using select_related() and prefetch_related() can reduce the number of database requests and improve performance. In this paper, a simple example is given to illustrate the functions of these two functions. Although QuerySet has been described in detail in the documentation, this article attempts to analyze the working mode from […]

  • Model of Django development – field type explanation


    Today, I will introduce the related field types and field options used to define models in Django development. Let’s start with the commonly used field types:1) AutoField: Self-increasing field type, which can be used when customizing the ID of the self-increasing type;2) BigAutoField: 64-bit integer self-increasing type;3) BigIntegerField: 64-bit integer class type;4) BinrayField: Binary data […]

  • Talk about Python’s built-in battery


    This article was originally published in the Public Number.【Python Cat】 Do not reproduce without authorization. Original address: https://mp.weixin.qqq.com/s/XzCqoCvcpFJt4A-E4WMqaA (1) Recently, I suddenly thought of a question:What concepts or idioms are unique to Python compared to other languages? After asking this question in the circle of friends, I got the most responses.——Pythonic。 This reply is not […]

  • Django-allauth Customization


    How to customize Django-allauth login template In django-allauth==0.36.0 In login page. There is no need to modify TEMPLATES settings Create an account directory under templates in the project folder To a temporary directory, such as: / tmp clone the allauth project git clone https://github.com/pennersr/django-allauth cd django-allauth/allauth/templates/account Copy base. HTML and login. HTML to account directoryI […]

  • Nginx + gunicorn environment for Django project in Ubuntu 18.04


    Today, I introduce how to build nginx + gunicorn environment for Django project in Ubuntu 18.04. The specific steps are as follows:1. Install gunicorn: PIP install gunicorn2. Start Django project with gunicorn: gunicorn project name. wsgi: application bind Install and configure nginx:When compiling and installing, several other packages need to be installed before installing […]

  • How to use pyCharm to debug python’s Django project


    Preface When debugging python, simple print can help us intuitively understand the code flow for debug, but sometimes it does complex data preprocessing. Simple use of print to debug code is far from meeting the requirements of developers. Deug with real-time observation of variable values can greatly increase the efficiency. The original use of vs […]

  • Preliminary Test of REST Framework for Front-end and Back-end Separation of Django


    When I first learned django, I used the method of separating static resources from interfaces, which would be very inconvenient in practice. The REST framework framework for front-end and back-end separation and writing back-end APIs was discovered. Here’s a preliminary attemptOfficial documents look very rudimentaryThis practice is mainly based on the official document steps to […]

  • Payment Process in the Development of Wechat Public Number


    Today, let’s talk about the payment process of Wechat Public Number Development in authorized web pages. There are several steps in the development of mini-public number:1. Get global access_token2. Access_token and refresh_token for obtaining web page authorization3. Get the signature of the page authorization (the front end is used to get the right to call […]

  • Python Cat Recommendation Series 7: What are Python introductory books?


    This article was originally published in the Public Number.【Python Cat】 Do not reproduce without authorization. Original address: https://mp.weixin.qq.com/s/ArN-6mLPzPT8Zoq0Na_tsg Recently, Cat Ge’s Python technology learning group has entered several special classmates: a junior three girl who is interested in programming, a teacher who has just started teaching Python in university, and an engineer in his forties […]

  • Learning Notes of Django Framework


    View Description of REST Framework Framework Based on Django (2) Development environment: Ubuntu 16.04 + Python 3.5x + Pycharm2018.2 Inheritance relationships between generic view base classes and extended classes containing methods and attributes Two base classes APIView class GenericAPIView class Main Descriptions of this ChapterGenericAPIView classrest_framework.generics.GenericAPIView Inheritance fromAPIViewAdding general support methods that may be used […]

  • Charset configuration of MySQL in Django


    After checking for half a day, the conclusion is that there is no way to configure charset of a table directly in django. All the searches on the Internet are charsets that allow people to configure the database directly, which makes people speechless. Add a row after the table creationCHARSET=utf8mb4Is it difficult? When MySQL is […]

  • Implementation of post complex object of Ajax acquired by Django


    1. The post object in django‘s request is empty (i.e. the post object that cannot be retrieved from the front Ajax transport) 1. Note django. middleware. csrf. CsrfViewMiddleware in django’s settings. 2. Or add {% CSRF%} in front and grammatical sugar on the method accepted in the background: @csrf_exempt, pay attention to adding reference module […]