从 angularJS 的 url 中删除 # 用于 SEO 的后端为 Django [英] Removing # from url of angularJS for SEO with backend as Django

查看:28
本文介绍了从 angularJS 的 url 中删除 # 用于 SEO 的后端为 Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道从 AngularJS 中删除哈希非常简单,但问题是后端在 Django 中.

I know removing hash from AngularJS is pretty straightforward but the problem is that the backend is in Django.

因此,除非使用F5"刷新页面,否则该应用可以正常工作.

So, the app works unless the page is refreshed using "F5".

所以,http://127.0.0.1:8000/account 如果按钮被点击则工作,但刷新页面给我 Page not found 作为服务器搜索它在 urls.py 文件

so, http://127.0.0.1:8000/account works if the button is clicked but refreshing the page gives me Page not found as the server searches for it in urls.py file

有人可以建议我解决这个问题吗?

Can someone please suggest me any fix for this ?

推荐答案

一切正常.当您刷新页面时,首先请求在服务器上得到处理(并转到 django 路由器).所以服务器应该知道它应该返回这个 URL 的角度页面.

Everything is right. When you refresh the page, firstly request gets processed on the server (and goes to django router). So server should know that it should return your angular page for this URL.

让我们假设包含 Angular 应用程序的页面存在于名为 index 的视图中.然后只需将此网址指向它:

Let's assume that your page that contains Angular application lives on view called index. Then just point this url to it:

urlpatterns = [
    url(r'^account/$', index), 
]

或将所有 url 指向您的视图(以防您不需要在没有 angular 的情况下处理任何其他 url):

or point all urls to your view (in case you don't need any other url's to be processed without angular):

//something like this, not really sure about the regex
urlpatterns = [
    url(r'^.*$', index), 
]

或类似的东西

urlpatterns = [
    url(r'^/account/.*$', index), 
]

您并不孤单:请参阅this这个.如您所见,这不是 Django 特有的问题,而是一些通用的客户端-服务器工作流程.

You're not alone with this issue: see this and this. So as you can see, it's not Django-specific trouble, but some general client-server workflow.

这篇关于从 angularJS 的 url 中删除 # 用于 SEO 的后端为 Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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