python - Flask 动态导航条
ringa_lee
ringa_lee 2017-04-18 09:03:34
0
3
466

问题一:

Flask配合jinja2模板怎样去制作动态的导航条?

nav_sql

字段 作用
id 主键
name 名字
body 内容

其实也就是为Flask扩展一个单页面访问功能,
但访问的方式是从网站顶部导航条进行的访问,并且动态增减.
目前能想到的就是在任何路由中都添加一条查nav_sql,然后render_template静态html时传参,但这样做的话,几乎每一部访问都要查询一次nav_sql.
有没有更简单的方法?

问题二:

就上面的问题,把导航条动态的输出到html里之后,需要访问链接吧???
以id作为访问关键词的话,例http://localhost/page/1 就是访问nav_sql里字段为1的单页
那我怎样去设计才能是http://localhost/page/zidingyi,通过这样的url方式去访问nav_sql id为1的单页内容呢?
这里我想到了为nav_sql再创建一个单独的字段,后端根据前台get请求的字段去匹配数据库是否存在,但如果是这样,怎样通过url_for在html生成链接呢?

感谢各位忙住.感谢!

ringa_lee
ringa_lee

ringa_lee

reply all(3)
洪涛

Cache your data, and update the cache when the table is updated, so that the data is loaded from memory every time, and there is no need to query the database every time

迷茫

I’ve thought about this too. What I think of is this: convert the navigation column into Pinyin and store it in a field, and then get this field to determine the specified content

刘奇

Recommended to use Pjax

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!