In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you what features Django 2.0 version has, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
I. Python compatibility
Django 2.0 supports Python3.4, 3.5, and 3.6. Django officially recommends the latest version of each series.
The most important thing is that Django 2.0 no longer supports Python2!
Django 1.11.x is the last version that supports Python2.7.
II. 2.0 new features
1. Simplified URL routing syntax
The syntax of the django.urls.path () method is simpler.
For example, the previous:
Url (r'^ articles/ (? P [0-9] {4}) / $', views.year_archive)
You can write:
Path ('articles//', views.year_archive)
The new syntax supports the mandatory definition of parameter types. In the example, only integer year parameters are received, no string types are accepted, and the "10000" year is legal (although it is 5 digits), unlike the previous regular which only accepts 4 digits.
The previous version of the django.conf.urls.url () method became django.urls.re_path (), but for backward compatibility, the old one was retained rather than immediately discarded. The django.conf.urls.include () method can now be imported from django.urls, that is, you can use from django.urls import include, path, re_path.
2.admin background is more mobile friendly.
Django's most popular admin background, with responsive features, supports mainstream mobile devices.
3.Window expression
The new Window expression allows you to add an OVER clause to the query set.
4. Small characteristic
Django.contrib.admin background
The new ModelAdmin.autocomplete_fields property and the ModelAdmin.get_autocomplete_fields () method can now use the Select2 search box on foreign keys and many-to-many fields.
Django.contrib.auth user authentication
The number of iterations for the PBKDF2 password hash default increased from 36000 to 100000.
Django.contrib.gis Geographic Framework
Added MySQL support for AsGeoJSON, GeoHash and GeoHash methods, isvalid and distance queries
Add Azimuth and LineLocatePoint methods to support PostGIS and SpatiaLite
All GEOSGeometry imported from GeoJSON have SRID collections
Add an OSMWidget.default_zoom attribute to customize the default zoom level of the map
Metadata is now readable and editable
Allow creation of GDALRaster objects in GDAL's internal virtual file system
The new GDALBand.color_interp () method returns the color description of the band.
Django.contrib.postgres database
New distinct parameter for ArrayAgg
New RandomUUID function
Django.contrib.postgres.indexes.GinIndex now supports fastupdate and gin_pending_list_limit parameters
The new GistIndex class allows GiST indexes to be created in the database
Inspectdb can now introspect JSONField and RangeFields.
Django.contrib.sitemaps site map
Add protocol parameters to the GenericSitemap constructor
Cache caching
Cache.set_many () now returns a list of key values that failed to insert
File Storage file storage
File.open () can now be used for context managers, such as with file.open () as f:
Forms form
SplitDateTimeWidget and SplitHiddenDateTimeWidget add date_attrs and time_attrs parameters to specify HTML attributes for DateInput and TimeInput
The new Form.errors.get_json_data () method returns a form error of dictionary type to accommodate the JSON type x response
Generic Views Universal View
The new ContextMixin.extra_context property allows context to be added to View.as_view ()
Management Commands management command
Inspectdb now treats unsigned integers of MySQL as PositiveIntegerField or PositiveSmallIntegerField
Added makemessages-- add-location option
Loaddata can now be read from standard input
Added diffsettings-- output option
Migrations migration
Added squashmigrations-- squashed-name option
Models model
New StrIndex database function
For Oracle databases, AutoField and BigAutoField now generate identity columns
QuerySet.iterator () added chunk_size parameter
QuerySet.earliest (), QuerySet.latest (), and Meta.get_latest_by can now be sorted by some fields
Added ExtractQuarter method for DateField and DateTimeField
Added TruncQuarter method to intercept DateField and DateTimeField to the first day of the quarter
Add db_tablespace parameters for class-based indexes
Add the of parameter to QuerySet.select_for_update (), but only support PostgreSQL and Oracle databases
QuerySet.in_bulk () added field_name parameter
CursorWrapper.callproc () now receives the optional dictionary type keyword parameter
QuerySet.values_list () added a named parameter to get the named tuple result.
The new FilteredRelation class allows you to add an ON clause to the query set
Pagination paging
Add Paginator.get_page () to handle all kinds of illegal page parameters and prevent exceptions
Requests and Responses request and response
Runserver servers now support HTTP 1.1
Templates template
To improve the usefulness of Engine.get_default () in third-party modules, it will now return the first of several DjangoTemplates engines configured in TEMPLATES instead of popping up an ImproperlyConfigured error
Custom template tags now receive mandatory keyword parameters
Tests test
Add multithreading support for LiveServerTestCase
Validators verifier
The new ProhibitNullCharactersValidator does not allow form input for CharField and its subclasses to be empty
Third, important backward incompatibility
1. Delete support for bytestrings in some places
For example, for reverse (), now use str () instead of force_text ().
2. The maximum length of AbstractUser.last_name is increased to 150.
If you have a custom user model that inherits AbstractUser, you need to generate and apply a database migration to make the maximum length of last_name 150.
If you need to maintain a 30-character limit for last_name, you can use a custom form as follows:
From django.contrib.auth.forms import UserChangeFormclass MyUserChangeForm (UserChangeForm): last_name = forms.CharField (max_length=30, required=False)
If you need to maintain this constraint in admin, you can use UserAdmin.form as follows:
From django.contrib.auth.admin import UserAdminfrom django.contrib.auth.models import Userclass MyUserAdmin (UserAdmin): form = MyUserChangeFormadmin.site.unregister (User) admin.site.register (User, MyUserAdmin)
3. QuerySet.reverse () and last () cannot be used in sliced query sets.
Using inversion and getting the most recent object on the sliced query set will pop up an exception, as follows:
Model.objects.all () [: 2] .reverse () Traceback (most recent call last):... TypeError: Cannot reverse a query once a slice has been taken.
4. The fields of the form no longer receive optional parameters as location parameters
To prevent run-time errors and improve reliability. It used to be similar to the following parameter passing method, but now it is wrong:
Forms.IntegerField (25,10)
To pass on like this:
Forms.IntegerField (max_value=25, min_value=10)
5. Index no longer receives location parameters
For example, the following usage will cause an exception:
Models.Index (['headline','-pub_date'], 'index_name')
To provide a parameter keyword, rewrite it as:
Models.Index (fields= ['headline','-pub_date'], name='index_name')
6. Call_command () will verify the options it receives
For administrative commands that use options instead of parser.add_argument () for customization, you need to add a stealth_options attribute, as follows:
Class MyCommand (BaseCommand): stealth_options = ('option_name',...)
7. SQLite now supports foreign key constraints
In addition, Django2.0 discards and removes some methods and properties.
These are all the contents of this article entitled "what are the features of Django 2.0?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.