客户端JS + Django的休息框架 [英] Client JS + Django Rest Framework

查看:141
本文介绍了客户端JS + Django的休息框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看完这篇文章关于分离服务器和客户机,独立REST API JSON服务器后和客户端?
我想知道如果这个问题也是在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中,这些2个独立的现象?

In Django, are these 2 separate phenomenons?


  1. Django是MVC。取出来看,有Django的作为后端,并只发送JSON。创建一个单独的说Emberjs或Angularjs应用。使这些客户端访问后端的REST资源。在这种情况下,你怎么可以把项目一起部署到Heroku的?你可以只部署一个JAVASCRIPT重客户到Heroku的,并且有它只是跟乌尔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,不要完全取出的观点,但Emberjs / Angularjs融入查看,但仍使用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的是一个应用服务器平台。这不是的真正的设计,提供静态code。

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

我previously采取的方法是正常建立Django的组成部分,没有供应了引导模板的JS应用程序根目录下的一切的单一视图。

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.

说我有一个角{,恩贝尔}应用程序住在 mydomain.com/app / ,然后在一切都将成为引导模板(包括查询序列化值从数据库),并调用JS自举方法来启动你的应用程序,然后应用程序接管路由从这一点来说,并呈现出它的意见。

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的框架/ Django的tasypie来了。

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

使用这种方法,并利用Django的管道和放大器; Django的博托的S3存储后端,你应该能够满足使用Django&放一个体面规模的项目; {角,恩贝尔}

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}

这篇关于客户端JS + Django的休息框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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