推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
azure
V2EX  ›  Python

flask-admin在后台生成的菜单怎么点都显示同一个view? 是哪里出问题了?

  •  
  •   azure · Oct 19, 2012 · 4072 views
    This topic created in 5089 days ago, the information mentioned may be changed or developed.
    from flask.ext.admin import Admin, BaseView, expose
    class ArticleView(BaseView):
    @expose('/')
    def index(self):
    return self.render('admin/index.html')

    @expose('/createarticle/')
    def test(self):
    return self.render('admin/index2.html')

    admin=Admin(app,name="test")
    admin.add_view(ArticleView(name=u"管理文章",endpoint="listarticle",category=u"文章"))
    admin.add_view(ArticleView(name=u"创建文章",endpoint="createarticle",category=u"文章"))


    后台能够正确生成出菜单,但是无论是点“管理文章”还是点"创建文章"。它都显示 index()的内容也就是渲染出 admin/index.html的内容。

    请问我是哪里出了问题?
    1 replies  •  1970-01-01 08:00:00 +08:00
    azure
        1
    azure  
    OP
       Oct 19, 2012
    当我把代码修改

    {{{
    def index(self):
    url=url_for(".test")
    return self.render('admin/index.html',url=url)
    }}}

    的时候。它输出了这样的内容。 为什么会有两个createarticle?

    /admin/createarticle/createarticle/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1082 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:00 · PVG 02:00 · LAX 11:00 · JFK 14:00
    ♥ Do have faith in what you're doing.