我无法更新Django的RedirectView.它一直引用状态为"301已永久移动"的旧URL. [英] I can't update Django's RedirectView. It keeps referring to the old URL with a status of 301 Moved Permenantly
问题描述
很抱歉,如果这个问题应该在Server Vault中.我真的无法分辨是编程错误还是服务器配置错误.
Sorry if this question was supposed to be in Server Vault. I couldn't really tell whether it's a programming error or a server configuration error.
我最近将我的git提交推送到了实时服务器,并且发现一些令人沮丧的事情.
I recently pushed my git commits to the live server and I noticed something very frustrating.
无论我如何编辑urls.py
,我似乎都无法更新RedirectView
!
No matter how I edit the urls.py
, I can't seem to update RedirectView
!
这是我的根mysite/urls.py
urlpatterns = patterns('',
url(r'^$', RedirectView.as_view(url=reverse_lazy('order_list')), name='home'),
url(r'^doors/', include('doors.urls')),
url(r'^accounts/', include('registration.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^{}/'.format(settings.DAJAXICE_MEDIA_PREFIX), include('dajaxice.urls')),
)
命名的URL order_list
来自我应用程序的urls.py
The named URL order_list
comes from one of my app's urls.py
urlpatterns = patterns('doors.views',
url(r'^order/$', OrderListView.as_view(), name='order_list'),
# And more URL patterns...
)
所以基本上我在上一次提交中只是将r'^orders/$'
更改为r'^order/$'
.但是,每当执行{% url home %}
时,我都注意到服务器不断尝试将其重定向到/doors/orders/
的 old 路径,而不是/doors/order/
.我还注意到重定向是301 Moved Permanently
.
So basically I simply changed r'^orders/$'
to r'^order/$'
in the last commit. But whenever I do {% url home %}
, I noticed the server keeps trying to redirect to the old path of /doors/orders/
instead of /doors/order/
. I also noticed that the redirect is a 301 Moved Permanently
.
因此,我尝试将permenant=False
添加到RedirectView
并重新启动服务器.但是它 still 转到了/doors/orders/
并且重定向仍然是301
(应该是302
)!
So I tried to add permenant=False
to RedirectView
and restarted the server. But it still goes to /doors/orders/
and the redirect is still 301
(it should have been 302
)!
为什么我的RedirectView
不重定向到更新的URL?
Why isn't my RedirectView
redirecting to the updated URL?
服务器信息
在Gentoo Linux上使用mod_wsgi和Django 1.4来运行Apache 2.2.21
Running Apache 2.2.21 using mod_wsgi with Django 1.4 on Gentoo Linux
推荐答案
原来,301
重定向已缓存在浏览器上!
It turned out that the 301
redirections are cached on the browser!
因此,我清除了浏览器的缓存,一切正常.当我不太了解301
和302
之间的区别时,很难知道在哪里寻找错误.我还意识到,由于我的RedirectView
本质上是一个占位符,直到我编写一个真正的家庭模板为止.我应该一直使用permanent=False
来创建302
.看看 docs 了解详情.
So I cleared my browser's cache and everything worked. It was hard knowing where to look for the error when I didn't really understand the difference between 301
and 302
that well. I also realized that since my RedirectView
is basically a placeholder until I write a real home template. I should be using permanent=False
to always create a 302
. Take a look at the docs for details.
这篇关于我无法更新Django的RedirectView.它一直引用状态为"301已永久移动"的旧URL.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!