问题描述
我知道从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),
]
或将所有网址指向您的视图(以防您不需要角度处理所有其他网址):
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),
]
并非只有一个人遇到此问题:请参见此和.因此,您可以看到,这不是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 for SEO的URL中删除#,后端为Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!