Have been following Flask Security protocols for user registration and login form for flask blog-post type app, using ORM peewee. Login works like a charm though registration is posing issue. Related Question How to use Flask-Security register view?
The App:
from flask import render_template, request, redirect, url_for
from models import *
@app.route('/')
def home():
return render_template('home.html',
posts=Post.select().order_by(Post.date.desc()))
@app.route('/login', methods=['GET', 'POST'])
def login():
return render_template('/security/login_user.html')
@app.route('/register', methods=['GET', 'POST'])
def register():
return render_template('/security/register_user.html')
Database Handler:
from flask import Flask
from flask_peewee.db import Database
from peewee import *
from flask_security import Security, PeeweeUserDatastore, UserMixin,
RoleMixin, login_required
import datetime
# Create app
app = Flask(__name__)
app.config['SECRET_KEY'] = 'super-secret'
app.config['DATABASE'] = {
'name': 'unnamed.db',
'engine': 'peewee.SqliteDatabase',
}
app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_REGISTER_URL'] = '/register'
app.config['SECURITY_LOGIN_USER_TEMPLATE'] = 'security/login_user.html'
app.config['SECURITY_REGISTER_USER_TEMPLATE'] =
'security/register_user.html'
app.config['SECURITY_RESET_PASSWORD_TEMPLATE'] =
'security/reset_password.html'
app.config['SECURITY_CHANGE_PASSWORD_TEMPLATE'] =
'security/change_password.html'
# Database connection object
db = Database(app)
user_datastore = PeeweeUserDatastore(db, User, Role, UserRoles)
security = Security(app, user_datastore)
Register User Form (The usual Flask_Security file taken from its git):
{% 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" %}
The logs show the output during rendering as:
- 127.0.0.1 - - [28/Apr/2017 22:07:51] "GET /login HTTP/1.1" 200 -
- 127.0.0.1 - - [28/Apr/2017 22:07:55] "GET /register/ HTTP/1.1" 404 -
URL with backspace for register is being rendered contrasted against the login. Have checked the whole thing for some hours now, but to no avail. Any hint what might be happening?