# 基于 Python Flask 的微博系统
[![Build Status](https://travis-ci.org/chenjiandongx/jianweibo.svg?branch=master)](https://travis-ci.org/chenjiandongx/jianweibo)
![jianweibo](https://github.com/chenjiandongx/jianweibo/blob/master/images/jianweibo.png)
简微博已部署在 heroku,[https://jianweibo.herokuapp.com/](https://jianweibo.herokuapp.com/),欢迎前往体验
开发环境:Windows10 + Python3
### PC 端
首页
![pc-0](https://github.com/chenjiandongx/jianweibo/blob/master/images/pc-0.gif)
个人信息页
![pc-1](https://github.com/chenjiandongx/jianweibo/blob/master/images/pc-1.gif)
注册
![pc-2](https://github.com/chenjiandongx/jianweibo/blob/master/images/pc-2.png)
### 移动端
首页
![mobile-0](https://github.com/chenjiandongx/jianweibo/blob/master/images/mobile-0.gif)
个人信息页
![mobile-1](https://github.com/chenjiandongx/jianweibo/blob/master/images/mobile-1.gif)
注册
![mobile-2](https://github.com/chenjiandongx/jianweibo/blob/master/images/mobile-2.png)
得益于 [flask-boostrap](https://github.com/mbr/flask-bootstrap),自适应 PC 端和移动端。不过毕竟免费,部署在 Heroku 速度一般吧。
## 项目介绍
[Flask](https://github.com/pallets/flask) 是基于 Pyhton 的 Web 开发框架,我觉得它的最大特点就是自由,框架本身提供了必备的所有内容,然后更多的功能的实现更依赖于第三方插件。也就是说,当你不满足现有的解决方案的时候你甚至可以给自己的 Web 项目动手写个增强插件来。
了解一个框架最好的方法就是动手实现一个项目,这个项目基本上是参照 [Flask Web Development
Developing Web Applications with Python](http://shop.oreilly.com/product/0636920031116.do) 这本书一行一行码出来的,不过对很多东西进行了修改。作者在 Github 上有这本书源码对应的仓库 [https://github.com/miguelgrinberg/flasky](https://github.com/miguelgrinberg/flasky)。
不过说句实在的,这本书项目还是有些大大小小的 bug,而且有些地方其实是可以优化代码的。当你自己一行一行码出来就会知道了。直接签出源码仓库运行会发现直接就报错的 -_-! 世上无难事,只要有 Google。
## 插件
项目使用的第三方插件
* [Flask-Bootstrap](https://github.com/mbr/flask-bootstrap)
* [Flask-HTTPAuth](https://github.com/miguelgrinberg/Flask-HTTPAuth)
* [Flask-Login](https://github.com/maxcountryman/flask-login)
* [Flask-Mail](https://github.com/mattupstate/flask-mail)
* [Flask-Migrate](https://github.com/miguelgrinberg/Flask-Migrate)
* [Flask-RESTful](https://github.com/flask-restful/flask-restful)
* [Flask-Script](https://github.com/smurfix/flask-script)
* [Flask-SQLAlchemy](https://github.com/mitsuhiko/flask-sqlalchemy)
* [Flask-SSLify](https://github.com/kennethreitz/flask-sslify)
* [Flask-WTF](https://github.com/lepture/flask-wtf)
## RESTful API
RESTful 部分是使用了 [flask-restful](https://github.com/flask-restful/flask-restful) 插件来完成的。下面是使用 [httpie](https://github.com/jakubroztocil/httpie) 在终端下的测试结果
### 评论
获取全部评论信息:https://jianweibo.herokuapp.com/api/v1.0/comment
```
$ http https://jianweibo.herokuapp.com/api/v1.0/comment
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 325
Content-Type: application/json
Date: Tue, 26 Sep 2017 14:57:59 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"comment": [
{
"authorID": 1,
"post": "Interesting",
"postID": 203,
"postTime": "Mon, 25 Sep 2017 14:19:40 GMT"
},
{
"authorID": 1,
"post": "Interesting",
"postID": 203,
"postTime": "Mon, 25 Sep 2017 14:19:31 GMT"
}
],
"totalCommentsCount": 2
}
```
获取单条评论信息:https://jianweibo.herokuapp.com/api/v1.0/comment/<int:id>
```
$ http https://jianweibo.herokuapp.com/api/v1.0/comment/1
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 112
Content-Type: application/json
Date: Tue, 26 Sep 2017 14:59:37 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"authorID": 1,
"post": "Interesting",
"postID": 203,
"postTime": "Mon, 25 Sep 2017 14:19:31 GMT"
}
```
### 微博
获取全部微博信息:https://jianweibo.herokuapp.com/api/v1.0/post
```
$ http https://jianweibo.herokuapp.com/api/v1.0/post
Connection: keep-alive
Content-Length: 3674
Content-Type: application/json
Date: Tue, 26 Sep 2017 15:00:31 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"post": [
{
"authorID": 7,
"posTime": "Tue, 19 Sep 2017 00:00:00 GMT",
"post": "Cras in purus eu magna vulputate luctus. Proin interdum mauris non ligula pellentesque ultrices."
},
{
"authorID": 72,
"posTime": "Sat, 16 Sep 2017 00:00:00 GMT",
"post": "Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Duis mattis egestas metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum aliquet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non mi."
},
{
"authorID": 54,
"posTime": "Wed, 20 Sep 2017 00:00:00 GMT",
"post": "Proin at turpis a pede posuere nonummy. Nunc rhoncus dui vel sem. Duis aliquam convallis nunc."
},
{
"authorID": 8,
"posTime": "Tue, 05 Sep 2017 00:00:00 GMT",
"post": "Aenean lectus. Praesent lectus. Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
},
..... # 内容太多,省略后面部分
}
```
获取单条微博信息:https://jianweibo.herokuapp.com/api/v1.0/post/<int:id>
```
$ http https://jianweibo.herokuapp.com/api/v1.0/post/2
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 385
Content-Type: application/json
Date: Tue, 26 Sep 2017 15:01:57 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"authorID": 72,
"posTime": "Sat, 16 Sep 2017 00:00:00 GMT",
"post": "Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Duis mattis egestas metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum aliquet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non mi."
}
```
发布微博:需要登录用户
```
$ http https://jianweibo.herokuapp.com/api/v1.0/post --auth <your-email>:<your-password> post="xxxxx"
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 16
Content-Type: application/json
Date: Tue, 26 Sep 2017 15:34:08 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"status": 200
}
```
### 用户
获取全部用户信息:https://jianweibo.herokuapp.com/api/v1.0/user
```
$ http https://jianweibo.herokuapp.com/api/v1.0/user
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 1025
Content-Type: application/json
Date: Tue, 26 Sep 2017 15:03:57 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
[
{
"id": 7,
"username": "helen"
},
{
"id": 8,
"username": "joyce"
},
{
"id": 3,
"username": "fred"
},
{
"id": 4,
"username": "marilyn"
},
{
"id": 9,
"username": "jean"
},
{
"id": 5,
"username": "ruth"
},
{
"id": 6,
"username": "maria"
},
..... # 内容太多,省略后面部分
}
```
获取单个用户信息:https://jianweibo.herokuapp.com/api/v1.0/user/<int:id>
```
$ http https://jianweibo.herokuapp.com/api/v1.0/user/5
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 159
Content-Type: application/json
Date: Tue, 26 Sep 2017 15:05:35 GMT
Server: gunicorn/19.7.1
Via: 1.1 vegur
{
"lastSeen": "Sun, 24 Sep 2017 16:46:13 GMT",
"memberSince": "Fri, 22 Sep 2017 00:00:00 GMT",
"postCount": 0,
"posts": [],
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
打开 http://127.0.0.1:5000/ 就可以看到程序已经在本地跑起来了 ## nose 测试 ``` shell $ cd app $ nosetests --with-coverage --cover-package=tests --verbosity=2 测试获取全部评论信息 ... ok 测试获取全部微博信息 ... ok 测试获取全部用户信息 ... ok 测试获取指定评论信息 ... ok 测试获取指定微博信息 ... ok 测试获取指定用户信息 ... ok 测试实例已经启动 ... ok 测试使用`TESTING-EMPTY`配置 ... ok 测试首页 ... ok 测试注册,登录,登出 ... ok -------- 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! <项目介绍> 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
资源推荐
资源详情
资源评论
收起资源包目录
基于 Python Flask 的微博系统 .zip (64个子文件)
code
.travis.yml 287B
migrations
README 38B
script.py.mako 494B
alembic.ini 770B
env.py 3KB
versions
7604c020c763_init_database.py 4KB
Makefile 33B
app
__init__.py 1KB
api_v1_0
__init__.py 84B
models.py 4KB
authentication.py 1KB
errors.py 203B
tests
__init__.py 0B
test_api.py 2KB
test_basics.py 678B
test_client.py 2KB
models.py 15KB
templates
403.html 182B
500.html 183B
followers.html 1KB
moderate.html 471B
post.html 702B
edit_profile.html 285B
_posts.html 2KB
404.html 187B
search_user.html 343B
base.html 3KB
index.html 1KB
user.html 2KB
_comments.html 2KB
auth
register.html 273B
unconfirmed.html 579B
login.html 273B
email
confirm.html 366B
change_password.html 284B
edit_post.html 292B
decorators.py 662B
main
__init__.py 401B
views.py 12KB
forms.py 2KB
errors.py 1KB
static
styles.css 2KB
fav.ico 9KB
auth
__init__.py 85B
views.py 4KB
forms.py 2KB
email.py 838B
manage.py 723B
test.sh 70B
Procfile 36B
requirements.txt 670B
.gitignore 1KB
images
mobile-2.png 10KB
mobile-0.gif 1.8MB
jianweibo.png 57KB
pc-2.png 17KB
pc-1.gif 676KB
pc-0.gif 2.61MB
mobile-1.gif 567KB
data-test-empty.sqlite 16KB
data-dev.sqlite 61KB
README.md 10KB
data-test-full.sqlite 61KB
config.py 2KB
共 64 条
- 1
资源评论
奋斗奋斗再奋斗的ajie
- 粉丝: 258
- 资源: 2229
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功