Или всё-таки посоветуете использовать SQLAlchemy?
Так же слышал про Flask-security, но использовать его крайне не хочется.
SELECT * FROM `user`
забрали всех юзеров, а потом сравниваете есть такой юзер или нет. А есть будет 100500 миллиардов юзеров? То что что делать? Каждый раз крутить такой ужас.cur.execute("""select id from user where login=%s and pass=%s""", (login, passw))
If cur.fetchone().get('id'):
return redirect(url_for('admin'))
@app.route('/test', methods=['POST'])
from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def main():
subprocess.Popen('python mysleep.py', shell=True, executable='/bin/bash')
return "Hello"
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
import time
time.sleep(10)
print("zzzzzzzzzzzz")
if request.method == 'POST' and search_form.validate_on_submit():
if request.method == 'POST':
if search_form.validate_on_submit():
print('form is valid')
else:
print('form is not valid')
choices=[(str(item.id), item.searcher) for item in Searcher.query.all()]
session['user_id'] = user_id
user_id = session.get('user_id')
if not user_id:
# Перекидываем на страницу с авторизацией
redirect(url_for('login'))
app.config.update(
MAIL_SERVER = 'two.yandex.com'
MAIL_USERNAME = 'user'
)
@app.before_request
def before_request():
lang = request.args.get('lang')
app.register_blueprint(main, url_prefix='main/<lang>/')
import os
# FLASK-MAIL SETTINGS
MAIL_USERNAME = os.getenv('MAIL_USERNAME', 'noreply@_your_host.com')
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD', '')
MAIL_DEFAULT_SENDER = os.getenv('MAIL_DEFAULT_SENDER', 'noreply@_your_host.com')
MAIL_SERVER = os.getenv('MAIL_SERVER', 'localhost')
MAIL_PORT = int(os.getenv('MAIL_PORT', '25'))
MAIL_USE_SSL = int(os.getenv('MAIL_USE_SSL', False))
hostname
from flask_mail import Mail, Message
mail = Mail(app)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)
echo 'Test msg' | mail -s 'test subj' your@mail.ru
from flask import Flask
from flask_mail import Mail, Message
import os
app = Flask(__name__)
# FLASK-MAIL SETTINGS
app.config['SECRET_KEY'] = 'dsfdsfdsfdsfdsf'
app.config['MAIL_USERNAME'] = os.getenv('MAIL_USERNAME', 'noreply@example.com')
app.config['MAIL_PASSWORD'] = os.getenv('MAIL_PASSWORD', '')
app.config['MAIL_DEFAULT_SENDER'] = os.getenv(
'MAIL_DEFAULT_SENDER', 'noreply@example.com')
app.config['MAIL_SERVER'] = os.getenv('MAIL_SERVER', 'localhost')
app.config['MAIL_PORT'] = int(os.getenv('MAIL_PORT', '25'))
app.config['MAIL_USE_SSL'] = int(os.getenv('MAIL_USE_SSL', False))
mail = Mail(app)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)
@app.route('/')
def home_page():
send_email('subj', 'noreply@example.com', ['ne@example.com'], 'Hello txt',
'<h1>Hello html</h1>')
return "100500"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
# config.py
class Config(object):
TESTING = False
# И еще конфиги разные
class ProductionConfig(Config):
DEBUG = False
LOGFILE = 'logs/Production.log'
class DevelopmentConfig(Config):
DEBUG = True
LOGFILE = 'logs/Development.log'
# app.py
from logging.handlers import RotatingFileHandler
from logging import Formatter
import logging
app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')
# -----------------------------------------------------------------------------
# Включение, отключение и ротация логов.
# -----------------------------------------------------------------------------
handler = RotatingFileHandler(app.config['LOGFILE'],
maxBytes=1000000, backupCount=1)
handler.setLevel(logging.DEBUG)
handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'))
# logging.disable(logging.CRITICAL) # Расскоментарь это для прекращения логов
app.logger.addHandler(handler)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
app.logger.info("My message")
return 'Hello, World!'
if __name__ == "__main__":
app.run(debug=True)
return render_template('js_post.html', payload=payload)
$.post('http://external.com', {'key':'value'}, function(data){
window.location = data.redirect;
});