Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望能有一份开发文档支持 #12

Open
1980744819 opened this issue Jan 3, 2019 · 1 comment
Open

希望能有一份开发文档支持 #12

1980744819 opened this issue Jan 3, 2019 · 1 comment

Comments

@1980744819
Copy link

想把这个项目做一个二次开发,要是有个开发文档就好了,或者也可以大概讲讲前后端哪个部分是干嘛的,用的技术站/库,以及它的作用,刚进来构建起来看代码确实一头雾水

@fy0
Copy link
Owner

fy0 commented Jan 4, 2019

这倒是真的,待我稍有余力吧。
其实这个项目,前端是非常典型的vue项目,和官方给的最佳实践基本一致,应该比较容易理解。
后端就麻烦一些,不过大体走向也不难说清:
view和Django的view是一个概念,其实就是mvc中的controller层,其中所有继承PeeweeView的类,都会对外暴露出get list set delete这几个接口(参见netapi.js的SlimViewRequest,其中update和set是同一个接口)。

@route('topic')
class TopicView(UserMixin, PeeweeView):
    model = Topic

例如上面这个例子,这个类的数据表对应到Topic这个model,几个接口映射到 /api/topic/xxx 下

后端对这几个接口有若干专门的钩子来控制(before_xxxx和after_xxx),用于数据校验和处理。
另外与用户有关的接口,除了PeeweeView之外还要继承UserMixin,这样才能取到self.current_user。

自定义接口在类中写个async方法,然后加上@route.interface('POST')@route.interface('GET')等装饰器就行了。

View中取params是self.params,取post数据是post = await self.post_data(),大致就是这样了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants