客户端JS + Django Rest框架

客户端JS + Django Rest框架

问题描述:

阅读有关分离服务器和客户端的文章后,单独的REST JSON API服务器和客户端?
我想知道Django中是否存在此问题。

After reading this article about separating server and client, Separate REST JSON API server and client? I want to know if this problem also exists in Django.

在Django中,这两个独立的现象是吗? >

In Django, are these 2 separate phenomenons?


  1. Django是MVC。取出视图,将django作为后端,并发送JSON。创建一个单独的Emberjs或Angularjs应用程序。使这些客户端访问后端的REST资源。在这种情况下,如何将项目合并到Heroku?你可以在Heroku中部署一个JAVASCRIPT-HEAVY-CLIENT,并且只需跟REST服务器通话?

  1. Django is MVC. Take out the view, have django as the backend and just send JSON. Create a separate say Emberjs or Angularjs app. Make these clients access backend's REST resources. In this case, how can you put the projects together to deploy to Heroku? Can you just deploy a "JAVASCRIPT-HEAVY-CLIENT" to Heroku, and have it just talk to ur REST server?

由于Django是MVC, t完全取出视图,但将Emberjs / Angularjs集成到View中,但仍然使用REST资源?这样,您可以将所有的angularjs组件/ js文件放入静态文件夹并部署到Heroku。

Since Django is MVC, don't completely take out the view, but integrate Emberjs/Angularjs into the View, but still use REST resources? In this way, you can put all the angularjs components/js files into the static folder and deploy to Heroku.

这些都一样吗?而现实的,你如何将它们放在一起才能部署到Heroku?

Are these the same? and realistically, how do you put them together to be able to deploy to Heroku?

Heroku是一个应用服务器平台。

Heroku is a application server platform. It's not really designed to serve static code.

我以前采取的方法是正常构建Django部分,并且具有一个单一的查看它为JS App根目录下的所有内容提供了一个引导模板。

The approach I've previously taken is to build the Django part normally, and have a single view that serves out a bootstrap template for everything under the JS App root.

说我有一个{Angular,Ember}应用程序生活在$ code> mydomain。 com / app / ,那么它下面的所有内容都将提供引导模板(包括从数据库查询的序列化值),并调用JS boostrap方法启动应用程序,然后应用程序接管路由点,并呈现出它的意见。

Say I have a {Angular,Ember} app living at mydomain.com/app/, then everything under that will serve the bootstrap template (which includes serialised values queried from database) and calls the JS boostrap method to startup your app, and then the app takes over routing from that point, and renders out it's views.

此时,所有的视图数据都来自django-rest-framework / django-tasypie。

At this point, all the data for the views is coming from django-rest-framework/django-tasypie.

使用此方法并利用django-pipeline& django-boto的S3存储后端,您应该能够使用Django& {Angular,Ember}

Using this method and leveraging django-pipeline & django-boto's S3 storage backend, You should be able to serve a decently sized project with Django & {Angular,Ember}