我已经使用Flash / AngularJS和socket.io建立了一个简单的Web应用程序。我有一个受密码保护的“管理员”页面,并具有一个MySQL后端,当身份验证成功时,该后端将填充设置页面。我遇到了一个问题,当我第一次加载页面时,在刷新浏览器页面之前,没有任何填充。
从我的app.py:
@app.route('/admin')
def admin():
"""
Called when we successfully navigate to the administrative settings page
:return: Flask.render_template, corresponding either to login.html or admin.html (depending on if credentials
were valid)
"""
global default_settings
my_logger.info('============= PAGE LOADED: settings')
# Refreshes default settings to make sure it is up to date with DB
default_settings = db_get_saved()
# If we have been logged out by the scan page, forces user to re-enter credentials
if not session.get('logged_in') and default_settings['user_pw'] != '':
return render('login.html', request.path)
# Otherwise renders the admin.html page
else:
return render('admin.html', request.path)
def render(template, path):
"""
Called by our Flask app when a new page is loaded. Renders corresponding HTML document
:param template: string, name of the HTML document to be rendered
:param path: string, path of this document
:param logo_menu: company logo to be displayed on front page in the menu bar
:param logo_footer: company logo to be displayed on front page in footer
:return: Flask.render_template, corresponds to the passed in parameters
"""
my_logger.info('Rendering page: ' + template)
logo = ''
if default_settings["company_logo"] != '':
logo = '/static/uploads/' + default_settings["company_logo"]
return render_template(template, app_name='My App', menu=create_menu(path), user_js='admin',
logo=logo)
页面呈现后,应使用app.py中名为fe_get_settings的函数填充表单,该函数从angular_controller.js中调用:
// ----------------------- Socket Event Handlers
socket.on('connect', function() {
/*
Listens for initial connect message from the socketio server. When connection occurs, requests default settings
from the DB
*/
socket.emit('fe_get_settings');
});
同样,一切正常,但是只有在我加载管理页面然后刷新它之后才可以。任何对此的见识将不胜感激!