Case insensitive urls for Django?

前端 未结 5 1834
野的像风
野的像风 2020-12-04 22:14

It seems by default django\'s url solver perform case sensitive search for solving url and differentiate between \'/Login\' and \'login\'. My url patterns are as follows.

5条回答
  •  星月不相逢
    2020-12-04 22:20

    Django 2.2 update

    According to this ticket:

    Support for inline flags in regular expression groups ((?i), (?L), (?m), (?s), and (?u)) was deprecated in Django 1.11 and removed in Django 2.1

    In Django 2.2 adding (?i) to the start of a pattern produces this exception:

    ValueError: Non-reversible reg-exp portion

    confusingly, adding it to the end produces this warning:

    DeprecationWarning: Flags not at the start of the expression

    The new suggested way to handle case insensative URLs in Django is to use a custom 404 handler.

    FWIW, that ticket also suggests "case-insensitive URLs aren't a good practice", however it doesn't provide any more arguement for this.

    There is a package on PyPi called django-icase that looks like a good option

提交回复
热议问题