Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
936 views
in Technique[技术] by (71.8m points)

django - Javascript MVC Frameworks and Server Side Frameworks

This question is regarding the co-extisense of two MVC Frameworks (on the client side and the server side).

Some Background: I am fairly new to web development, but am a very proficient programmer. I learnt javascript and Django only recently. The Front end for my app is quite Javascript extensive and hence I decided to use a framework. I am currently reading up on the available frameworks and I am inclining towards backbone.js + jquery.

My problem is that I don't fully understand how a MVC framework like backbone.js can co-exist with a server side framework like Django.

From what I understood of backbone.js, when there is a change to a model, the corresponding views related to the model are automatically updated. Here, we are referring to the "views" of the Client side framework right? Would such a "view" communicate with the backend framework's "controller"?

How would a possible directory structure be? Is such an architecture bad?

Does the question make sense? or am I lost?

Edit: To add some clarity: I guess my essential question is : How a complex single-page JS web application be structured on the client-side (espertially if u are using a client side framework)? Specifically I'm curious about how to cleanly structure the application in terms of its model objects, UI components, any controllers, and objects handling server persistence.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can speak in terms of Rails/Backbone, but I can't imagine that Django would be much different.

First, a client-side MVC framework like Backbone isn't just for single-paged apps. You can also use it to add some rich interaction to one or many views of a more traditional app. They simply provide structure and data abstractions on the client.

Next, these client-side frameworks are designed specifically to work with your back-end MVC frameworks. Backbone.js (since you tagged it specifically) models and collections work with REST services. They will talk via GET/POST/PUT/DELETE verbs and will ultimately communicate with your controllers on the back-end when they make asynchronous requests.

In the case of Backbone, it talks JSON instead of HTML. In the case of Rails, this is really easily handled in the controller. If the request is an HTML one, then you return a view as HTML. If it is a JSON request (*.json or Content-type) then the controller returns a JSON representation of the data. I am assuming that it is as easy in Django as it is in Rails to have the same controller respond to multiple content requests (HTML, XML, JSON, etc)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...