Giter Club home page Giter Club logo

Comments (1)

fy0 avatar fy0 commented on May 31, 2024

这倒是真的,待我稍有余力吧。
其实这个项目,前端是非常典型的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(),大致就是这样了。

from icarus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.