2017-06-22 14 views
0

私は別々に動作する2つの別々の管理ページを作成しようとしています。 2つの別々の管理ページが正常に動作しましたが、2番目の管理ページでAdminIndexViewをどのように設定できるかわかりません。Flask Admin 2つの管理パネル

class FlaskAdminIndexView(AdminIndexView): 
    @expose('/') 
    def index(self): 
     if not current_user.is_authenticated: 
      return redirect(url_for('security.login')) 
     elif (current_user.is_authenticated) and (not current_user.has_role('first_admin')): 
      return redirect(url_for('post_user.index_entry')) 
     else: 
      return super(FlaskAdminIndexView, self).index() 

first_admin = flask_admin.Admin(app, 'RCIGM ADMIN', base_template='my_master.html', 
          template_mode='bootstrap3', 
          index_view=FlaskAdminIndexView()) 

上記のコードスニペットは、ユーザーのアクセシビリティを最初の管理ページに設定する方法です。

class FlaskSecondAdminIndexView(AdminIndexView): 
    @expose('/') 
    def index(self): 
     if not current_user.is_authenticated: 
      return redirect(url_for('security.login')) 
     elif (current_user.is_authenticated) and (not current_user.has_role('second_admin')): 
      return redirect(url_for('post_user.index_entry')) 
     else: 
      return self.render('admin/base.html') 
      #return super(FlaskAdminIndexView, self).index() 

second_admin = flask_admin.Admin(app, 'SITE ADMIN', url='/site_admin', 
          base_template='my_master.html', endpoint='site_admin', 
          template_mode='bootstrap3', index_view=FlaskSecondAdminIndexView()) 

上記のコードは、私の第二の管理ページのためである、と私は以下のような青写真衝突エラーが発生します。

Traceback (most recent call last): 
     File "/Users/genom003dm/PycharmProjects/sample_accessioning_dev/app/run.py", line 2, in <module> 
     from app import app 
     File "/Users/genom003dm/PycharmProjects/sample_accessioning_dev/app/__init__.py", line 55, in <module> 
     from app.views.post_inputs import post_user_blueprint 
     File "/Users/genom003dm/PycharmProjects/sample_accessioning_dev/app/views/post_inputs.py", line 65, in <module> 
     from app.security_layer import generate_registration_token, confirm_token, user_datastore, \ 
     File "/Users/genom003dm/PycharmProjects/sample_accessioning_dev/app/security_layer.py", line 249, in <module> 
     template_mode='bootstrap3', index_view=FlaskSecondAdminIndexView()) 
     File "/Users/genom003dm/sample_accessioning_dev_virtual_env/lib/python3.5/site-packages/flask_admin/base.py", line 522, in __init__ 
     self._set_admin_index_view(index_view=index_view, endpoint=endpoint, url=url) 
     File "/Users/genom003dm/sample_accessioning_dev_virtual_env/lib/python3.5/site-packages/flask_admin/base.py", line 566, in _set_admin_index_view 
     self.add_view(self.index_view) 
     File "/Users/genom003dm/sample_accessioning_dev_virtual_env/lib/python3.5/site-packages/flask_admin/base.py", line 540, in add_view 
     self.app.register_blueprint(view.create_blueprint(self)) 
     File "/Users/genom003dm/sample_accessioning_dev_virtual_env/lib/python3.5/site-packages/flask/app.py", line 64, in wrapper_func 
     return f(self, *args, **kwargs) 
     File "/Users/genom003dm/sample_accessioning_dev_virtual_env/lib/python3.5/site-packages/flask/app.py", line 946, in register_blueprint 
     (blueprint, self.blueprints[blueprint.name], blueprint.name) 
    AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x104f95a20> and <flask.blueprints.Blueprint object at 0x104e500b8>. Both share the same name "admin". Blueprints that are created on the fly need unique names. 

ご協力いただきありがとうございます。

答えて

0

AdminIndexViewを作成するときは、urlendpointを渡す必要があります。例えば

from flask import Flask 
from flask_admin import Admin, expose, AdminIndexView 


app = Flask(__name__) 


@app.route('/') 
def index(): 
    return ''' 
     <a href="/first-admin/">Click me to get to First Admin!</a><br> 
     <a href="/second-admin/">Click me to get to Second Admin!</a> 
     ''' 


class FirstAdminIndexView(AdminIndexView): 
    @expose('/') 
    def index(self): 
     return 'Hello From first admin :{}.'.format(self) 


class SecondAdminIndexView(AdminIndexView): 
    @expose('/') 
    def index(self): 
     return 'Hello From second admin :{}'.format(self) 


first_admin = Admin(
    app, 
    template_mode="bootstrap3", 
    url='/first-admin', 
    endpoint='first', 
    index_view=FirstAdminIndexView(url='/first-admin', endpoint='first') 
) 


second_admin = Admin(
    app, 
    template_mode="bootstrap3", 
    url='/second-admin', 
    endpoint='second', 
    index_view=SecondAdminIndexView(url='/second-admin', endpoint='second') 
) 


if __name__ == '__main__': 
    app.run(port=5000, debug=True) 
関連する問題