如何使Django与Angular URL兼容

编程入门 行业动态 更新时间:2024-10-23 03:26:33
本文介绍了如何使Django与Angular URL兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Django提供的Angular 2应用程序中,如何在重新加载页面时使Angular 2 URL与Django一起使用?

In Angular 2 app that's served by Django, how to make the Angular 2 URL work with Django when reloading the page?

具体来说,假设Django服务的页面的网址为localhost:8000/home.该页面包含3个标签,其中一个是Angular应用.单击该选项卡将显示Angular应用程序,并且URL更改为localhost:8000/home/ng_app.现在,如果使用 this url 刷新浏览器,则Django将显示404,这是有道理的,因为Django应用程序中不存在localhost:8000/home/ng_app.

Specifically, say a page served by Django has the url localhost:8000/home. The page contains 3 tabs and under one of which is an Angular app. Clicking on that tab shows the Angular app, and the url changes to localhost:8000/home/ng_app. Now if the browser is refreshed with this url, Django will show a 404, which makes sense because localhost:8000/home/ng_app is not present in the Django app.

那么如何使Angular URL工作呢? (输入localhost:8000/home/ng_app会导致Angular应用而不是404).谢谢!

So how to make the Angular URL work? (entering localhost:8000/home/ng_app leads to the Angular app instead of 404). Thanks!

推荐答案

您应该考虑在角度应用中将哈希爆炸用作URL.结帐本教程是通过谷歌搜索发现的,该URL也使用了刘海.

You should consider using hash bangs in your angular app as URLs. Checkout this tutorial I found by googling which also uses has bangs for URLs.

通过这种方式,角度应用程序URL不会与您的Django应用程序冲突,并且Angular会出于路由目的将其选中

In this way the angular app URLs wont conflict with your Django app and Angular would pick it up for routing purposes

更多推荐

如何使Django与Angular URL兼容

本文发布于:2023-10-13 10:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Django   Angular   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!