问题描述
有没有人使用 Flask-Security
扩展名进行身份验证?我如何获得注册视图的工作?
我指的是上面的链接。
@ app.route('/ register',methods = ['GET'])
def register():
return render_template('security / register_user.html')
我不想扩展默认类,我只想在我的网站中包装默认的注册视图布局,所以我做到了。
{%extendslayout.html%}
{%block title%}上传{%endblock%}
{%block body%}
{%fromsecurity / _macros.htmlimport render_field_with_errors,render_field%}
{%includesecurity / _messages.html%}
< h1>注册< / h1>
< form action ={{url_for_security('register')}}method =POSTname =register_user_form>
{{register_user_form.hidden_tag()}}
{{render_field_with_errors(register_user_form.email)}}
{{render_field_with_errors(register_user_form.password)}}
{%if register_user_form。 password_confirm%}
{{render_field_with_errors(register_user_form.password_confirm)}}
{%endif%}
{{render_field(register_user_form.submit)}}
< / form>
{%includesecurity / _menu.html%}
{%endblock%}
我得到以下错误?
werkzeug.routing.BuildError
BuildError :('security.register',{},None)
你只需要在你的应用程序配置中启用它:
app = Flask(__ name__)
app.config ['SECURITY_REGISTERABLE'] = True
。
如果需要,还有另外一个配置值可以改变URL:
app.config ['SECURITY_REGISTER_URL '] ='/ create_account'
其他Flask-Security配置信息可以在这里找到:
Has anyone used Flask-Security
extension for authentication? How do I get register view to work?
http://packages.python.org/Flask-Security/customizing.html
I am referring to link above.
@app.route('/register', methods=['GET'])
def register():
return render_template('security/register_user.html')
I don't want to extend the default class, I just want to wrap the default registration view in my site layout so I did this.
{% extends "layout.html" %}
{% block title %}upload{% endblock %}
{% block body %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% include "security/_messages.html" %}
<h1>Register</h1>
<form action="{{ url_for_security('register') }}" method="POST" name="register_user_form">
{{ register_user_form.hidden_tag() }}
{{ render_field_with_errors(register_user_form.email) }}
{{ render_field_with_errors(register_user_form.password) }}
{% if register_user_form.password_confirm %}
{{ render_field_with_errors(register_user_form.password_confirm) }}
{% endif %}
{{ render_field(register_user_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}
And I am getting the following error?
werkzeug.routing.BuildError
BuildError: ('security.register', {}, None)
You don't need to create the view. A default one is included in Flask-Security.You just need to enable it in your flask app config:
app = Flask(__name__)
app.config['SECURITY_REGISTERABLE'] = True
With this, the '/register' route should work.
There is another configuration value to change the URL if desired:
app.config['SECURITY_REGISTER_URL'] = '/create_account'
Other Flask-Security configuration information can be found here:http://pythonhosted.org/Flask-Security/configuration.html
这篇关于如何使用Flask-Security注册视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!