flask-admin不正确的相对网址

时间:2018-04-01 17:35:13

标签: flask flask-admin

我正在尝试创建一个简单的管理员来编辑mongo集合。我已经发布了以下代码。它完全在本地工作或作为码头工人容器。但是,当我在我们的微服务架构中部署它时,应用程序位于:SERVER_NAME / TEAM_NAME / APP_NAME /。

使用@ app.route设置的Flask路线正常工作。但是,管理模板中的网址不正确,并且始终直接在SERVER_NAME处启动,忽略了团队名称和应用名称。实际页面和资源位于正确的URL,但找不到静态资源的URL。如何确保在flask-admin中生成的网址还考虑了相对网址?

代码:

import os
import flask_admin
from wtforms import form, fields
from flask_admin.contrib.pymongo import ModelView, filters


# User admin
class WordPairsForm(form.Form):
    text = fields.StringField("Text")
    language = fields.SelectField("Language", choices=[("de", "german"), ("en", "english"), ("pl", "polish")])
    label = fields.SelectField("Label", choices=[("badword", "bad word"), ("no_stay", "no overnight stay")])
    active = fields.BooleanField("Active", default="checked")


class WordPairsView(ModelView):
    column_list = ("text", "language", "label", "active")
    column_sortable_list = ("text", "language", "label", "active")
    column_searchable_list = ("text",)
    column_filters = (
        filters.FilterLike("text", "Text"),
        filters.FilterNotLike("text", "Text"),
        filters.FilterEqual("language", "Language", options=[("de", "german"), ("en", "english"), ("pl", "polish")]),
        filters.FilterEqual("label", "Label", options=[("badword", "bad word"), ("no_stay", "no overnight stay")]),
        filters.BooleanEqualFilter("active", "Active")
    )
    form = WordPairsForm

    def create_form(self):
        _form = super(WordPairsView, self).create_form()
        return _form

    def edit_form(self, obj):
        _form = super(WordPairsView, self).edit_form(obj)
        return _form

    def get_list(self, *args, **kwargs):
        count, data = super(WordPairsView, self).get_list(*args, **kwargs)

        return count, data

    def get_url


def add_admin(app):
    admin = flask_admin.Admin(
        app,
        name="CQAS Admin",
        url=os.getenv(
            "F_ADMIN_URL",
            "/admin"
        ),
        static_url_path=os.getenv("F_ADMIN_STATIC_URL", None),
        subdomain=os.getenv("F_ADMIN_SUBDOMAIN", None),
        endpoint=os.getenv("F_ADMIN_ENDPOINT", None)
    )
    admin.add_view(WordPairsView(app.data.data, "WordPairs"))

0 个答案:

没有答案