Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What do you need to pay attention to when upgrading Django from 1.8 to 2.0

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what do you need to pay attention to when upgrading Django from 1.8to 2.0". In daily operation, I believe many people have doubts about what they need to pay attention to when upgrading Django from 1.8to 2.0. the editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of" what do you need to pay attention to when upgrading Django from 1.8to 2.0"! Next, please follow the editor to study!

1, print

In Python3, print changes from statement to function, so all print statements need to be changed to print ()

2,on_delete

In django 2, on_delete=models.XXX is no longer the default option in models and needs to be explicitly specified

3, reverse

In the new version of django, these packages no longer belong to core, but belong to django.urls packages, and the import path needs to be changed

4, MIDDLEWARE

In the new version of django, the key value of middleware is changed from MIDDLEWARE_CLASSES to MIDDLEWARE

5, SessionAuthenticationMiddleware

The middleware SessionAuthenticationMiddleware is no longer needed in the new version of django.

6, render_to_response

In the new version of django, render_to_response is not built and used, but the render function is used instead.

7, from _ _ unicode__ to _ _ str__

After the new version of python, the models definition of django needs to be changed from _ _ unicode__ to _ _ str_

Deprecation of 8 has_key' 's' Dict's method

The has_key method of the dictionary in the new version of python is cancelled. It is recommended to use "str" in dict to judge.

9, Direct assignment to the forward side of a many-to-many set is prohibited

In the new version of django, orm many-to-many external keys are no longer assigned with equal values, but are replaced by set method.

New_list = [obj1, obj2, obj3]

E.related_set = new_list = = "e.related_set.set ([obj1, obj2, obj3])

10, Only byte strings can be passed to C code

When using PyCryptodome for AES encryption and decryption, pay attention to the use of decode and encode in python3

How do I convert byte to unicode when I output 11J html? (the web page output is baked')

Str can convert BYTES into unicode;bytes ('', 'utf8') reverse operation.

12, orm migrate

After django upgrade, makemigration will do it again. Migrate may need to add on_delete=models.XXX manually.

13What is the versatility of virtualenv in 13J python?

If you install the new version of python3 explanation, you can copy the directory by changing the path in the active file.

At this point, the study on "what to pay attention to when upgrading Django from 1.8 to 2.0" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report