Skip to Content
Flask Web开发:基于Python的Web应用开发实战(第2版)
book

Flask Web开发:基于Python的Web应用开发实战(第2版)

by Miguel Grinberg
August 2018
Intermediate to advanced
230 pages
6h 42m
Chinese
O'Reilly Media, Inc. Beijing
Content preview from Flask Web开发:基于Python的Web应用开发实战(第2版)
关注者
135
followed_by() 方法分别在左右两边的一对多关系中搜索指定用户,如果找到了就返回
True。发起查询之前,这两个方法都确认了指定的用户有没有 id,以防创建了用户,但是
尚未提交到数据库。
如果你从
GitHub
上克隆了这个应用的
Git
仓库,那么可以执行
git checkout
12a
检出应用的这个版本。这个版本包含一个数据库迁移,检出代码后记得
要执行
flask db upgrade
命令。
现在,关注功能在数据库中的部分完成了。你可以在
GitHub
上的源码仓库找到对于这个
数据库关系的单元测试。
12.2
 在资料页面中显示关注者
如果用户查看一个尚未关注用户的资料页面,页面中要显示一个“
Follow
”(关注)按钮,
如果查看已关注用户的资料页面则显示“
Unfollow
”(取消关注)按钮。而且,页面中最好
能显示出关注者和被关注者的数量,再列出关注和被关注的用户列表,并在相应的用户资
料页面中显示“
Follows You
”(关注了你)标志。对用户资料页面模板的改动如示例
12-4
所示。添加这些信息后的资料页面如图
12-3
所示。
示例
12-4
 
app/templates/user.html
:在用户资料页面上部添加关注信息
{% if current_user.can(Permission.FOLLOW) and user != current_user %}
{% if not current_user.is_following(user) %}
<a href="{{ url_for('.follow', ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python机器学习基础教程

Python机器学习基础教程

Andreas C. Müller, Sarah Guido
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
程序设计导论:Python语言实践

程序设计导论:Python语言实践

罗伯特 塞奇威克, 凯文 韦恩, 罗伯特 唐德罗

Publisher Resources

ISBN: 9787115489456