двойное отрицание not None?
from django.contrib.auth import authenticate
user = authenticate(username='john', password='secret')
if user is not None:
# A backend authenticated the credentials
else:
# No backend authenticated the credentials
это же разные проверки, нет?
Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. Also, beware of writing "if x" when you really mean "if x is not None" -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!
Спасибо. Я знал, что разные, но они очень похожи
Ну если мы знаем, что user не может к False приводиться, то можно и if user: использовать, как я понимаю
Обсуждают сегодня