问题
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.
I recently pushed my git commits to the live server and I noticed something very frustrating.
No matter how I edit the urls.py
, I can't seem to update RedirectView
!
Here is my root 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')),
)
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...
)
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
.
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
)!
Why isn't my RedirectView
redirecting to the updated URL?
Server info
Running Apache 2.2.21 using mod_wsgi with Django 1.4 on Gentoo Linux
回答1:
It turned out that the 301
redirections are cached on the browser!
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.
来源:https://stackoverflow.com/questions/10513470/i-cant-update-djangos-redirectview-it-keeps-referring-to-the-old-url-with-a-s