Django url warning urls.W002

Sorry if this question seems a little redundant, but this is what really bothers me.

I have an API set written in Django defined by the following URLs.

# urls.py
import ...
urlpatterns = [
    url(r"^api/v1/account", include(profile.urls))
]

and

# profile/urls.py
import ...
urlpatterns = [
    url(r"^$", AccountAPI.as_view()),
    url(r"^/login$", LoginAPI.as_view()),
    url(r"^/logout$", LogoutAPI.as_view())
]

This configuration should only allow URLs:

/api/v1/account
/api/v1/account/login
/api/v1/account/logout

This work is for my purpose, but I have such warnings (I have several APIs defined with this rule, and the list of warnings is longer):

?: (urls.W002) Your URL pattern '^/login$' has a regex beginning with a '/'. Remove this slash as it is unnecessary.
?: (urls.W002) Your URL pattern '^/logout$' has a regex beginning with a '/'. Remove this slash as it is unnecessary.

If I delete the slash , the server will not check the URLs I have defined. To do this, I must have a slash to the first level of URLs, for example:

# urls.py
import ...
urlpatterns = [
    url(r"^api/v1/account/", include(profile.urls))
]

And this will cause the account invocation to end with a slash, which I don't want.

, URL- , , , , .

- ? URL- , ? ?

+4
3

, URL- , /api/v1/account/ /api/v1/account/login/.

- , url ^/ , W002 .

Django 1.10.2 , APPEND_SLASH=False . . 27238 .

+2

, SILENCED_SYSTEM_CHECKS.

:

SILENCED_SYSTEM_CHECKS = ['urls.W002', 'security.W019']
+3

, .

? - ?

Django, URL- . , Django admin URL . Django URL-.

URL Dispacher, :

, URL . , , ^/articles.

0

Source: https://habr.com/ru/post/1665649/


All Articles