Flask引导定制Flask安全

2024-05-19 09:49:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Flask security,我无法集成flaskbootstrap来定制登录、注册和其他页面的用户界面。在

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

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

有人能告诉我我缺少什么吗?在

这是登录的代码_用户.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 %}

这是布局.html公司名称:

^{pr2}$

以下是存储模板的文件结构:

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

这里是init的代码:

''' 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

Tags: fromimportformconfigappflaskfieldhtml

热门问题