本文整理汇总了Python中application.app.config方法的典型用法代码示例。如果您正苦于以下问题:Python app.config方法的具体用法?Python app.config怎么用?Python app.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类application.app
的用法示例。
在下文中一共展示了app.config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_profile
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def update_profile():
if request.method == 'POST':
for item in app.config['USER_PROPERTIES']:
if request.form.has_key(item['variable']):
if item['type'] == 'boolean':
if request.form[item['variable']] == 'yes':
setattr(current_user, item['variable'], True)
else:
setattr(current_user, item['variable'], False)
if item['type'] == 'integer':
setattr(current_user, item['variable'],
item['choices']
.index(request.form[item['variable']]))
db.session.commit()
flash(_('Profile updated'), 'info')
return redirect(url_for('users.profile'))
return render_template('update_profile.html', user=current_user,
profile_form=app.config['USER_PROPERTIES'])
示例2: upload
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def upload():
# import pdb
# pdb.set_trace()
if request.method == "POST":
typ = request.form.get('type')
file = request.files.get('file')
result = False
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
save_as = os.path.join(app.config['UPLOAD_DIR'], filename)
try:
file.save(save_as)
except Exception as e:
return render_template('error_code/404.html', msg='Failed to save file...[Err:{0}]'.format(e))
else:
result = move_file(typ, save_as, filename, backup=True, linkit=True)
if not result:
flash('error:Failed To Upload file..., Try again...')
else:
flash('info:File uploaded Successfully!')
return render_template('upload/upload.html')
示例3: authenticate
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def authenticate(u, p):
if u and p:
if u in (current_app.config['ADMIN_MAIL'],):
p_salt = p + current_app.config["SECRET_KEY"]
e_salt = chaabi + current_app.config["SECRET_KEY"]
d = hashlib.sha384()
e = hashlib.sha384()
d.update(p_salt.encode())
e.update(e_salt.encode())
return d.hexdigest() == e.hexdigest()
else:
return False
else:
return False
示例4: enable
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def enable(token):
email = ''
try:
email = ts.loads(token, salt=email_confirm_key, max_age=84600 * 3)
except:
flash('error:Invalid Enable Link!!')
abort(404)
if email == current_app.config['ADMIN_MAIL']:
global DISABLE_LOGIN, NOTIFIED
DISABLE_LOGIN = False
NOTIFIED = False
else:
flash('error:Invalid Enable Link!!!')
abort(404)
flash('info:Account enabled successfully!')
return redirect(url_for('auth.login'))
示例5: profile
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def profile():
projects = list(Project.query.all())
branches = list(Branch.query.filter(Branch.owner==current_user).all())
return render_template('profile.html', projects=projects, branches=branches,
user=current_user,
properties=app.config['USER_PROPERTIES'])
示例6: get_locale
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def get_locale():
# if a user is logged in, use the locale from the user settings
# user = getattr(g, 'user', None)
# if user is not None:
# return user.locale
#print(request.accept_languages.best_match(app.config['LANGUAGES'].keys()))
#return request.accept_languages.best_match(app.config['LANGUAGES'].keys())
return 'en'
示例7: internal_server_error
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def internal_server_error(e):
message = repr(e)
trace = traceback.format_exc()
trace = string.split(trace, '\n')
timestamp = (datetime.fromtimestamp(time.time())
.strftime('%Y-%m-%d %H:%M:%S'))
if current_user.is_authenticated:
user = current_user.username
else:
user = 'anonymous'
gathered_data = ('message: {}\n\n\n'
'timestamp: {}\n'
'ip: {}\n'
'method: {}\n'
'request.scheme: {}\n'
'request.full_path: {}\n'
'user: {}\n\n\n'
'trace: {}'.format(message, timestamp,
request.remote_addr, request.method,
request.scheme, request.full_path,
user, '\n'.join(trace)))
# send email to admin
if app.config['TESTING']:
print(gathered_data)
else:
mail_message = gathered_data
msg = Message('Error: ' + message[:40],
body=mail_message,
recipients=[app.config['ADMIN_MAIL']])
mail.send(msg)
flash(_('A message has been sent to the administrator'), 'info')
bookcloud_before_request()
return render_template('500.html', message=gathered_data), 500
示例8: __repeat_bg_thread
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def __repeat_bg_thread():
try:
BackgroundThreadManager.__start_ssh_threads()
# loop the background thread (default = every 30 seconds)
timer = app.config['BG_THREAD_TIMER']
th = threading.Timer(timer, BackgroundThreadManager.__repeat_bg_thread)
th.daemon = True
th.start()
except Exception as e:
app.logger.critical("Stopping the program due to the unexpected error...")
app.logger.critical(e)
thread.interrupt_main()
示例9: set_logging
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def set_logging():
logging_level_app = app.config['LOGGING_LEVEL_APPLICATION']
logging_level_werkzeug = app.config['LOGGING_LEVEL_WERKZEUG']
logging_level_socketio = app.config['LOGGING_LEVEL_SOCKETIO']
logging_level_engineio = app.config['LOGGING_LEVEL_ENGINEIO']
logging_level_to_file = app.config['LOGGING_LEVEL_TO_FILE']
logging_max_bytes = app.config['LOGGING_MAX_BYTES']
log_format = "%(asctime)s [%(levelname)s] %(message)s"
logging.basicConfig(format=log_format, level=logging_level_app)
#if sys.version_info[0] == 3:
# console log handler
console_log_handler = logging.StreamHandler()
console_log_handler.setFormatter(logging.Formatter(log_format))
app.logger.addHandler(console_log_handler)
# logging to a file
file_handler = RotatingFileHandler("application/log/error.log", maxBytes=logging_max_bytes, backupCount=1)
file_handler.setLevel(logging_level_to_file)
file_handler.setFormatter(logging.Formatter(log_format))
app.logger.addHandler(file_handler)
# werkzeug logging
logging.getLogger('werkzeug').setLevel(logging_level_werkzeug)
logging.getLogger('werkzeug').addHandler(file_handler)
# SocketIO logging
logging.getLogger('socketio').setLevel(logging_level_socketio)
logging.getLogger('engineio').setLevel(logging_level_engineio)
logging.getLogger('socketio').addHandler(file_handler)
logging.getLogger('engineio').addHandler(file_handler)
示例10: __init__
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def __init__(self):
if app.testing:
self.__database_name = app.config['MONGO_DATABASE_NAME'] + "_test"
else:
self.__database_name = app.config['MONGO_DATABASE_NAME']
self.__database_ip = app.config['MONGO_DATABASE_HOST']
self.__port = app.config['MONGO_DATABASE_PORT']
self.db = self.__connect_db()
if app.config['DEBUG']:
MachineData.drop_collection()
示例11: main
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def main():
app_host = app.config['APPLICATION_HOST']
app_port = app.config['APPLICATION_PORT']
try:
BackgroundThreadManager.start()
socketio.run(app, host=app_host, port=app_port)
except KeyboardInterrupt:
pass
#app.run(host=app_host, port=app_port)
示例12: get_img
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def get_img(img_path):
ext = os.path.basename(img_path).split('.')[-1]
if ext and ext in app.config['IMAGE_VALID_EXTS']:
return send_from_directory(app.config['IMAGE_FOLDER'], img_path)
else:
abort(404)
示例13: get_doc
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def get_doc(doc_path):
ext = os.path.basename(doc_path).split('.')[-1]
if ext and ext in app.config['DOCS_VALID_EXTS']:
stat.update_download_count(doc_path, Utility.get_ip(request))
return send_from_directory(app.config['DOCS_FOLDER'], doc_path, as_attachment=True)
else:
abort(404)
示例14: move_file
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def move_file(typ, src, name, backup=True, linkit=True):
result = False
link_names = {'dp': 'dp.jpg', 'resume': 'Resume.docx'}
if typ == 'dp':
target = os.path.join(app.config['IMAGE_FOLDER'], name)
result = __move(src, target, backup, linkit, link_names.get('dp'))
elif typ == 'resume':
target = os.path.join(app.config['DOCS_FOLDER'], name)
result = __move(src, target, backup, linkit, link_names.get('resume'))
elif typ == 'blog':
target = os.path.join(app.config['IMAGE_FOLDER'], name)
result = __move(src, target, backup=False, linkit=False, link_name=None)
return result
示例15: load
# 需要导入模块: from application import app [as 别名]
# 或者: from application.app import config [as 别名]
def load():
loader = AddonLoader(verbose=True, logger=app.logger, recursive=False, lazy_load=False)
loader.set_addon_dirs([os.path.join(BASE_DIR, app.config['DASHBOARD_MODS'])])
loader.set_addon_methods(['execute', 'template', 'get_result'])
loader.load_addons()
return loader, loader.get_loaded_addons(list_all=True)