在Django中反应还是作为独立反应? [英] React in Django or React as a standalone?

查看:39
本文介绍了在Django中反应还是作为独立反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何创建django react应用程序以及实现它的最佳方法.从创建django react应用程序的此链接开始,可以找到实现该应用程序的几种方法.

I have been researching how to create django react application and the best way to go about implementing it. From this link on creating a django react app states a few way to go about implementing it.

一种方法是生成一个webpack,然后使用django加载该webpack,另一种方法是将其作为2个独立的应用程序运行.

One way is to generate a webpack and using django to load the webpack another is to run it as 2 separate applications.

在自己的前端" Django应用程序中进行响应:加载单个HTML模板并让React管理前端"与作为独立API的Django REST +作为独立SPA的React"相比,明显有什么好处

What are the obvious benefits of "React in its own "frontend" Django app: load a single HTML template and let React manage the frontend" vs "Django REST as a standalone API + React as a standalone SPA"

因为我看不到需要生成Webpack并以Django模板加载应用程序,而您可以在其中创建独立的react应用程序并使用Django REST进行通信?

Because I do not see a need of generating a webpack and loading the application in django template where you could create a standalone react app and use Django REST for communication?

推荐答案

拆分前端和后端将获得的第一件事就是模块化.由于您的应用程序逻辑与用户界面完全分离,因此您有了一个稍微模块化的Web应用程序.模块化有助于很多事情,包括测试,可读性和可维护性.

The first thing you would gain by splitting your frontend and your backend is modularity. With your application logic completely separated from your user interface, you have a slightly more modular web application. Modularity aids in a number of things, including testing, readability, and maintainability.

还具有独立的API,任何人或任何前端都可以重用您的后端逻辑,无论它是移动应用程序还是您甚至可以想象的CLI,都可以重用.

Also with a separate API, your backend logic can be reused by any anyone or any frontend be it a mobile app or anything you could imagine even your CLI.

如果我理解正确,那么您的目标是将您的create react应用程序的最终捆绑包包含在Django页面中.

Your goal would be to include the final bundle of your create react app in a Django page if I understood correctly ?

这篇关于在Django中反应还是作为独立反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆