Django3.0 forward to support asynchronous communication

The last two years, Django version upgrade much faster, 2.0 still did not take long, will soon be up to 3.0.

Let's take a look at the official roadmap and timetable:

1

version number Release date Updated stop Stop modification date
3.0 2019-12 2020-08 2021-04
3.1 2020-08 2021-04 2021-12
3.2 LTS 2021-04 2021-12 2024-04

We can see that in December 2019 the upcoming release 3.0, upgrade to 4.0 in 2022, but we still feel 2.2 yesterday.

This gives the majority of users and learners bring a certain amount of pressure to learn and upgrade costs, but also on behalf of Django's very healthy ecosystem, users increased steadily, rapid iteration function, is a good sign, we should actively embrace change, refuse behind.

Next, let's look at what new things and new changes in 3.0 exactly.

Python compatibility

The following version 3.6 is no longer supported, supports only 3.6,3.7,3.8 or later.

(Django's strategy has always been in accordance with the latest Django Please use the latest python.)

ASGI

This is the biggest change and enhance Django3.0!

By supporting ASGI, Django3.0 start with a full-duplex asynchronous communication capabilities to address their biggest shortcomings, no longer being criticized! (Tornado supporters say take this thing for two days is not the day)

Support ASGI not replace existing WSGI, but a supplement, which means that we now have two servers running the model.

It should be noted that only started after ASGI-based server, it supports asynchronous communication functions. In ASGI mode, and supports both asynchronous and synchronous communication. (WSGI the synchronous communication mode only)

Django official document of a deployment ASGI https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ , is worth learning about.

The introduction of ASGI also brought some things to consider: Django now monitors asynchronous event loop, and prevents you from asynchronous call is marked in the context 异步不安全of the code, such as ORM operations (note that this is not to say that ORM can not be used). If you encounter SynchronousOnlyOperationan error, please double-check code and all database operations moved to the sub-thread synchronization.

MariaDB

Support MariaDB 10.1 or later.

PostgreSQL

By adding a model Meta.constraintsoption, you can add exclusion constraints in PostgreSQL database.

Filter expression

You can now use Boolean expressions directly output QuerySet filtering operation, without first polymerized and then filtered.

Model field enumerable options

New enumeration class TextChoices, IntegerChoicesand Choicesthey are all Field.choicessubclasses. That you did not have in CharFieldadding the choicesparameters, you can create a direct TextChoicesobject.

Small function

The following are some minor changes (not some unusual)

django.contrib.admin

  • To ModelAdmin.list_displayadd admin_order_fieldsupport
  • The new ModelAdmin.get_inlines()method allows to specify a request or according to the model instance inlinemode
  • Select2 database upgrade from version 4.0.3 to 4.0.7
  • jQuery upgrade from version 3.3.1 to 3.4.1.

django.contrib.auth

  • PasswordResetConfirmViewYou can add new reset_url_tokenproperties

  • New BaseBackendclasses to simplify custom backend authentication.
  • New get_user_permissions()method, a mirror image of conventional get_group_permissions()methods.
  • Username HTML pages, widgets email and password fields added to autocompleteattribute to better interact with the browser device.
  • When executing createsuperusera command, if you do not provide the appropriate command line parameters in non-interactive mode, you will be returned to the environment variables and password required field.
  • ManyToManyFieldYou can now use REQUIRED_FIELDS.
  • The new UserManager.with_perm()method will return the user has specified permission.
  • The default password hashes PBKDF2 iteration count is increased to 180,000 from 150,000.

django.contrib.sessions

The new get_session_cookie_age()method allows to dynamically specify the lifetime of the session cookie.

Models

  • New database hash function MD5, SHA1, SHA224, SHA256, SHA384, and SHA512.

  • Add a Sign database functions.

  • FilePathFieldNow accepts callable objects

  • Self-referencing ManyToManyFieldfield allows symmetric intermediate table

  • AvgAnd Sumaggregation are now supported distinctparameters, deduplication.

  • Add SmallAutoFieldfield, similar to the AutoFieldfield, except that it allows only a small range of values, for example from 1 to 32767, so it would be more secure.

  • AutoField, BigAutoFieldAnd SmallAutoFieldit is inherited IntegerField, BigIntegerFieldand SmallIntegerField, so the verifier system checks and accordingly are inherited.

  • FileField.upload_toNow supported pathlib.Path.

  • CheckConstraint It is supported on MySQL 8.0.16+.

Django3.0 not backward compatible

(Brief overview)

  • The following PostgreSQL 9.5 is no longer supported
  • 12.2 The following Oracle no longer supports
  • Delete the official Python 2 compatibility related API
  • Some security settings now have a more secure default: X_FRAME_OPTIONSnow defaults 'DENY'. SECURE_CONTENT_TYPE_NOSNIFFNow by default True.
  • 1.2.0 The following are no longer supported pywatchmanlibrary

Django3.0 discarded some functions

django.utils.encoding.force_text() and smart_text()

Some of django.utils and http, translation, text and other related content.

Django 3.0 deleted function

The following methods, properties and settings are deleted:

  • django.db.backends.postgresql_psycopg2Module
  • django.shortcuts.render_to_response() method
  • DEFAULT_CONTENT_TYPESet up
  • HttpRequest.xreadlines() method
  • Field.from_db_value()And Expression.convert_value()methods
  • QuerySet.earliest()And latest()the field_namekeyword arguments

  • django.utils.http.cookie_date() method
  • staticfilesAnd admin_statictemplate tag library
  • django.contrib.staticfiles.templatetags.staticfiles.static() method

to sum up

We can see from the release notes, the core supports ASGI change Django3.0 is asynchronous communication, other minor changes are generally basic user experience does not come out.

Asynchronous communication function is said to be the django-channle this external libraries included in, the official Django as one of the core functions of the standard. Anyway, HTML5 websocket will be the direct communication and the Django. Django-based web to achieve chat rooms, web QQ, web pages and other micro-channel real-time communication applications will become simple, and the length of the polling we can say goodbye.

(More relevant content and Django recent changes, please pay attention to my official website www.liujiangblog.com, related to the latest instructional video will also be released the first time!)

Guess you like

Origin www.cnblogs.com/django-dev/p/11627118.html