0%

如何结合Django,React搭建前后台框架

setting up a Django project with React.

Django,React搭建前后台框架主要有以下思路(which are common to almost every web framework):

  1. React in its own “frontend” Django app: load a single HTML template and let React manage the frontend (difficulty: medium)

    • 作者推荐,
  2. Django REST as a standalone API + React as a standalone SPA (difficulty: hard, it involves JWT for authentication)
    demo都没怎么有设置权限,,作者有给提供连接,Django的登陆, drf的权限和认证,

    • 样例1

      • 这个通过CORS_ORIGIN_WHITELIST 这个设置可以控制权限?要不就跨域.
      • 感觉这个挺好的,然后集合了下面的用户请求,
    • 样例2

      这个是利用framework 发送用户名密码返回token然后存储,然后之后的请求都带上这个token

      1
      curl -X POST -d "username=admin&password=xxxx" http://localhost:8000/auth
  3. Mix and match: mini React apps inside Django templates (difficulty: simple)

    • 不推荐对新手