0

我正在使用 Flask-security,但无法集成 Flask-bootstrap 以自定义登录、注册和其他页面的用户界面。

该项目托管在这里: https ://github.com/fbenavides69/control-escolar

我已经通过 pip 安装了这些包,并且可以呈现登录、注册和其他页面,但由于某种原因,我无法让它们呈现用户引导程序。我已经按照 c/p 应用程序模板目录下的安全页面的建议来覆盖外观,但没有任何成功。

有人可以指出我所缺少的吗?

这是 login_user.html 的代码:

{% extends "layout.html" %}

{% block body %}
    {{super()}}

    {% include "navbar.html" %}

    {% block content %}
        {{super()}}

        {% from "security/_macros.html" import render_field_with_errors, render_field %}
        {% from "security/_form_macros.html" import render_field %}
        <div class="container">
        {% include "security/_messages.html" %}
        <h1>{{ _('Login') }}</h1>
        <form action="{{ url_for_security('login') }}" method="POST" name="login_user_form">
          {{ login_user_form.hidden_tag() }}
          {{ render_field_with_errors(login_user_form.email) }}
          {{ render_field_with_errors(login_user_form.password) }}
          {{ render_field_with_errors(login_user_form.remember) }}
          {{ render_field(login_user_form.next) }}
          {{ render_field(login_user_form.submit) }}
        </form>
        {% include "security/_menu.html" %}
        </div>

    {% endblock content %}

{% endblock body %}

这是layout.html:

{% extends "bootstrap/base.html" %}

{% block html_attribs %} 
    lang="sp" 
{% endblock %}
{% block metas %}
    <meta charset="utf-8">
{% endblock %}

这是存储模板的文件结构:

application
+-site
  +-templates
    +-security
      +- login_user.html
      +- register_user.html

这里是初始化文件的代码:

''' Flask Application Factory

    Blueprint Flask application using the factory pattern,
    with configuration setup and blueprint module registration
'''
from flask import Flask
from flask_bootstrap import Bootstrap
from flask_security import Security
from flask_security import SQLAlchemyUserDatastore
from flask_debugtoolbar import DebugToolbarExtension
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
from .models import db
from .models import User
from .models import Role
from .admin import admin


def create_app():
    ''' create_app

        input:
            None

        output:
            app -- flask web application instance

        Read configuration values in the following order:
            1) default, values which can be overwritten later
            2) intance, for your eyes only not stored in repo values
            3) environment, selectable values from:
                - development
                - stagging
                - production

        Setup web interface with Bootstrap framework
    '''

    # Initialize app
    app = Flask(__name__, instance_relative_config=True)

    # Load default config values
    app.config.from_object('config.default')
    # Load instance config values not stored in repo
    app.config.from_pyfile('config.py')
    # Load environment config values
    app.config.from_envvar('APP_CONFIG_FILE')

    # Create database connection
    db.init_app(app)

    # Instantiate Admin section
    admin.init_app(app)

    # Initialize bootstrap
    Bootstrap(app)

    # Setup Flask-Security
    security = Security(app, SQLAlchemyUserDatastore(db, User, Role))

    # Debug = True to enable the toolbar
    toolbar = DebugToolbarExtension(app)

    # Load blueprint modules
    from application.site.routes import mod as site
    from application.api.routes import mod as api

    # Register blueprint modules for use
    app.register_blueprint(site)
    app.register_blueprint(api, url_prefix='/api')

    return app
4

1 回答 1

1

事实证明,“模板”目录必须直接放在“应用程序”文件夹下才能正常工作:

application
  +-site
  +-templates
    +-security
于 2018-02-24T04:43:02.683 回答