在具有Angular前端的简单Django Rest Framework应用程序中会发生什么? [英] What happens in a simple Django Rest Framework application that has an Angular front end?

查看:109
本文介绍了在具有Angular前端的简单Django Rest Framework应用程序中会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经学习Django一段时间了,我发现这张图片很有帮助:

I've been learning Django for some time now, and I found this image helpful:

我现在正在研究Angular JS,并且试图弄清楚每个组件(指令,控制器和服务?)如何交互以及是否存在类似的循环".此博客看起来已经接近了回答我的问题.

I'm now delving into Angular JS, and I'm trying to figure out how each of the components (Directives, Controllers and Services ?) interacts and if there is a similar 'cycle'. This blog looks like it comes close to answering my question.

但是,如果我们有一个Django-Rest-Framework端点来提供上述示例中的书籍,那么图片会有什么不同?

But how is the picture different if we have a Django-Rest-Framework end point providing the books in the above example?

我们是否需要Django或Angular的URL解析?或更负责任的,这是先例吗?

Do we want URL resolution from Django, or Angular? Or more answerabley, which takes precedent?

当我们说localhost:8000/books时,事情发生的一般顺序是什么?

What is the general order that things happen in when we go to say localhost:8000/books ?

  • urls.py抓住了吗?

urls(r'^books',angular_redirect)

如果是的话,该函数(angular_redirect)需要渲染什么才能使角度响应?

If so what does that function (angular_redirect) need to render to get angular to respond?

角度布线是否可以捕捉到这一点?

Does angular routing catch this?

 $routeProvider.when('/books', {templateUrl: 'partials/book_partial.html', controller: 'MyBookCtrl'});

那么这是否意味着我的控制器随后注册了一个连接为localhost:8000:/book_list.json的服务,是否需要在urls.py中注册该服务?

So does this mean my controller then registers a service hooked up to say localhost:8000:/book_list.json and does that need to be registered in the urls.py?

如果我们完全依赖于angular进行路由,那么Angular如何知道从何处获取DRF JSON.我见过程序包,该程序包使您可以在angular中使用django模型. JS,但我不确定这是否会使图片或多或少变得复杂.

How does Angular know where to get the DRF JSON, if we're wholly relying on angular for routing. I've seen this package that lets you use the django models in the angular JS, but I'm not certain if that makes the picture more or less complicated.

很抱歉,如果涉及面太广,我是个新手,我想弄清楚这些技术的一些一般概念.有关缩小此问题以使其易于回答的任何建议,将不胜感激.

Apologies if this is overly broad, I'm very new and trying to get my head round some of the general concepts of these technologies. Any advice on narrowing this question so it's answerable would be appreciated.

推荐答案

您的问题有一个简单的答案:Angular处理前端,而Django(和DRF)处理后端,其中包括URL.完全由Angular提供支持的网站上的用户永远不要直接访问Django提供的URL,除非最初的页面可以提供页面结构和JS本身.

Your question has a simple answer: Angular handles the front end and Django (and DRF) handles the back end, and that includes URLs. Users on a fully Angular-powered site should never directly hit a URL that is served by Django, except possibly for the initial page that serves the page structure and JS itself.

除此之外,两者之间的唯一交互是当Angular通过Ajax调用专门从Django请求JSON时.这很可能与用户的导航事件有关,但是同样可以在定时的基础上或通过某种Websocket功能触发.

Apart from that, the only interaction between the two is when Angular specifically requests JSON from Django, via an Ajax call. That may well be in relation to a navigation event by the user, but just as equally could be triggered on a timed basis or via some kind of websocket functionality.

这篇关于在具有Angular前端的简单Django Rest Framework应用程序中会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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