Why did Django 1.9 replace tuples () with lists [] in settings and URLs?

后端 未结 2 427
盖世英雄少女心
盖世英雄少女心 2021-02-03 19:59

I am bit curious to know why Django 1.9 replaced tuples () with lists [] in settings, URLs and other configuration files

I just upgraded to Django 1.9 a

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 20:42

    In the release notes of 1.9, there is:

    Default settings that were tuples are now lists

    The default settings in django.conf.global_settings were a combination of lists and tuples. All settings that were formerly tuples are now lists.

    So it appears that it was just done for consistency. Both tuples and lists should work fine. If you use a tuple with 1 element, remember the comma (1,) because otherwise it's not a tuple but simply an expression in parens.

    As for urlpatterns, those used to be defined using a patterns() function, but that was deprecated in Django 1.8, as a list of url instances works fine. As the function will be removed in the future, it shouldn't be used in new apps and projects.

提交回复
热议问题