简体   繁体   English

JS前端框架(ember,Angular等)如何与后端框架(例如Django,Rails等)一起使用?

[英]How does JS front-end framework (ember, Angular etc.) work with back-end frameworks(such as Django , Rails etc.)?

I have used django for few projects and used heroku to deploy. 我使用django进行了一些项目,并使用heroku进行了部署。 I have been looking into front-end frameworks such as Ember, Angular and was confused as to how it will integrate with a django project. 我一直在研究诸如Ember,Angular之类的前端框架,并对如何将其与django项目集成感到困惑。 Reading some Docs, it appears i need to have developed a REST api for my app using the backend framework in order for Javascript framework to communicate with the database. 阅读一些文档,看来我需要使用后端框架为我的应用程序开发一个REST api,以便Javascript框架与数据库进行通信。 In this case the backend mostly works as a thin layer that provides access to the database. 在这种情况下,后端通常充当提供对数据库访问权限的薄层。 But what if I use something like parse and their Javascript API, would I even need a Backend Framework like Django? 但是,如果我使用诸如parse及其Javascript API之类的东西,我甚至需要像Django这样的后端框架吗?

How frameworks like Django will work with frameworks like Angular or Ember depends a lot on what you want to do with it and what your view on architecture is in general, so it's hard to give a one true answer. Django之类的框架如何与Angular或Ember之类的框架一起使用将在很大程度上取决于您要使用它以及您对体系结构的总体看法,因此很难给出一个真实的答案。 But in general no, you don't need one, but you still might want one. 但通常不,您不需要一个,但您仍然可能想要一个。

You don't need one because as you surmised frameworks like this want a REST API (although it doesn't have to be specifically REST-like that is definitely the most common way of doing it), so you wouldn't be using Django templating or anything like that. 您不需要一个,因为您推测这样的框架需要一个REST API(尽管不必专门使用REST-like,这绝对是最常用的方式),因此您不会使用Django模板或类似的东西。

But one of the good part of using these frameworks, and the part that makes the question impossibly to answer, is that they don't care about the backend! 但是使用这些框架的好处之一,就是使问题不可能回答的部分,是它们不关心后端!


Why does this matter? 为什么这么重要?

When backend and frontend is properly separated you get a great deal more flexibility on both ends. 当后端和前端正确分开时,您将在两端获得更大的灵活性。 As long as they work with the API you can build them however you see fit. 只要它们可以与API一起使用,您就可以根据自己的喜好来构建它们。 If you find Djangos ORM nice to work with you can use it to create the API. 如果您发现可以很好地使用Django的ORM,则可以使用它来创建API。 If you feel like using something super lightweight like Flask you can do that. 如果您想使用像Flask这样的超轻量级产品,可以这样做。 If you want to host a Java app on AWS you can do that, etc, etc. 如果您想在AWS上托管Java应用程序,则可以这样做,等等,等等。

The key is that you can let your backend needs determine how you build the backend, and your frontend needs determine how you build the frontend. 关键在于您可以让您的后端需求确定如何构建后端,而前端需求则确定您如何构建前端。 That's why the question can't be answered. 这就是为什么无法回答问题的原因。 You strictly speaking don't need Django or any smilar framework but depending on what the backend is going to do you might want some of the features from them, like the ORM or the general structure. 严格来说,您不需要Django或任何类似的框架,但根据后端的用途,您可能需要其中的某些功能,例如ORM或常规结构。

So look at what your backend needs to do in order to serve the API and choose based on that. 因此,请查看您的后端需要做什么才能提供API并根据该API进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MVC框架进行前端和后端 - Using MVC frameworks for front-end and back-end 如何同时使用AngularJS作为前端框架和ASP.NET MVC作为后端框架? - how to use AngularJS as front-end framework and ASP.NET MVC as back-end framework together? 带有PHP + MySQL后端的JS(Angular)前端用户特权 - JS(Angular) Front-End user privileges with PHP + MySQL Back-End 休息后端,Angular.js前端很多问题 - Rest back-end, Angular.js front-end lots of questions 如何将对象数组从 Angular 前端传递到 C# 后端 - How to pass Array of Objects from Angular Front-end to C# Back-end 为什么我的Angular前端无法将正确的$ http.get参数传递给Django后端? - Why won't my Angular front-end pass correct $http.get parameters to Django back-end? 您如何格式化数据,以便Angular,Backbone,Ember等MV *框架可以轻松使用它们? - How do you format data so that it can be easily consumed by MV* frameworks like Angular, Backbone, Ember, etc.? 将jhipster后端和前端分成两个项目? - Separating jhipster back-end and front-end into two projects? Web应用程序前端和后端的误解 - Web Application front-end and back-end misunderstanding 后端vs前端控制的Web应用程序 - back-end vs front-end controlled web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM