Найти - Пользователи
Полная версия: синтаксис переменная = 1 или 2
Начало » Python для новичков » синтаксис переменная = 1 или 2
1 2
yohoho
             if config.listen_port_https == 443:
                self.redirect("https://" + request.host + request.uri)
Мне нужно config.listen_port_https равен 443 или 80.
Пробовал
             if config.listen_port_https == 443, 80:
                self.redirect("https://" + request.host + request.uri)
             if config.listen_port_https == 443 else 80:
                self.redirect("https://" + request.host + request.uri)
Оба неработают. Как это записать?
AD0DE412
 if [int(input('test: '))][0] in [1, 2]:
    print("--> 1 or 2")
else:
    print("-->", None)
или
 print("--> 1 or 2") if [int(input('test: '))][0] in [1, 2] else print("-->", None)

зы работает с вводом цифр
yohoho
OK.
              if config.listen_port_https == [443, 80]:
                self.redirect("https://" + request.host + request.uri)
Не вызвало ошибки, но редирект domain.com на https://domain.com не сработал.
Предположительно
         # we serve contents only over HTTPS
        if not self.isSecure() and (config.transport != 'HTTP'):
            if config.listen_port_https == 443:
                self.redirect("https://" + request.host + request.uri)
            else:
                self.redirect(
                    b"https://" + request.host + b":" + str(config.listen_port_https).encode('utf-8') + request.uri)
            self.finish()
return
Используется для редиректа на https. Но это нифига не работает.
         # we serve contents only over HTTPS
        if not self.isSecure() and (config.transport != 'HTTP'):
            if config.listen_port_https == [443, 80]:
                self.redirect("https://" + request.host + request.uri)
            self.finish()
            return
Тоже не прокатило.
Сервер висит на 443 и 80. В обоих случаях должно редиректить на https. ХЗ что не так.
AD0DE412
что выдает print(config.listen_port_https, type(config.listen_port_https))
yohoho
AD0DE412
if in :
print(“–> 1 or 2”)
else:
print(“–>”, None)

или

print(“–> 1 or 2”) if in else print(“–>”, None)
Вообще эта логика, издевательство над мозгом.
Так и не понял к чему это.
AD0DE412
http://python.su/forum/post/208176/
AD0DE412
yohoho
синтаксис переменная = 1 или 2
yohoho
Вообще эта логика, издевательство над мозгом.
Так и не понял к чему это.
пример
1 или 2 = True
остальное = False те None
конечно коректней будет False

yohoho
AD0DE412
что выдаетconfig.listen_port_http
Я это даже в консоль вывести не смог
         # we serve contents only over HTTPS
        if not self.isSecure() and (config.transport != 'HTTP'):
		print config.listen_port_https
            if config.listen_port_https == [443, 80]:
                self.redirect("https://" + request.host + request.uri)
            self.finish()
            return
Не сработало.
yohoho
         # we serve contents only over HTTPS
        if not self.isSecure() and (config.transport != 'HTTP'):
		print(config.listen_port_https, type(config.listen_port_https))
            if config.listen_port_https == [443, 80]:
                self.redirect("https://" + request.host + request.uri)
            self.finish()
            return
Тоже не прокатило. Зачем “type(config.listen_port_https)”. Разве есть такой тип переменной?
AD0DE412
yohoho
“type(config.listen_port_https)
это вопрос для объекта “ты кто?”
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB