Пример #1
0
from flask_wtf import FlaskForm, Form
from wtforms import IntegerField, validators


class ContactForm(FlaskForm):
    guess = IntegerField(label='Guess number',
                         validators=[
                             validators.NumberRange(min=1,
                                                    max=100,
                                                    message='Test numberrange')
                         ])


app = Flask(__name__)
app.config.update(
    **settings.as_dict()
    # DEBUG=True,
    # SECRET_KEY='This key must be secret!',
    # WTF_CSRF_ENABLED=False,
    # NUM = randint(1, 101)
)


@app.route('/', methods=['GET'])
def home():
    return render_template('home_template.html', status="GET")


@app.route('/guess', methods=['GET', 'POST'])
def guess():
    if request.method == 'POST':
Пример #2
0
import sentry_sdk
from sentry_sdk.integrations.sanic import SanicIntegration

from simple_settings import settings

from . import web_exceptions

if settings.SENTRY_DSN:
    sentry_sdk.init(dsn=settings.SENTRY_DSN,
                    integrations=[SanicIntegration()],
                    environment=settings.SENTRY_ENVIRONMENT,
                    debug=settings.DEBUG)

app = Sanic(__name__)
app.config.update(settings.as_dict())

db = Gino()
db.init_app(app)


async def server_error_handler(request, exc):
    data = {
        'data': exc.data,
        'message': exc.message,
        'message_code': exc.message_code,
        'message_human': exc.message_human
    }
    return response.json(data, status=exc.status_code)

Пример #3
0
from simple_settings import settings as ss


class AttrDict(dict):
    def __init__(self, *args, **kwargs):
        super(AttrDict, self).__init__(*args, **kwargs)
        self.__dict__ = self


settings = AttrDict(ss.as_dict())
SETTINGS_LOGGING = settings.get('LOGGING')
SETTINGS_LISTEN = settings.get('LISTEN')
SETTINGS_API = settings.get('API')
SETTINGS_DATABASE = settings.get('DATABASE')
SETTINGS_DEFAULT_SERVER_DATETIME_FORMAT = settings.get(
    'DEFAULT_SERVER_DATETIME_FORMAT')