Django redirect for legazy php url
Basically what I want to do is:
urlpatterns = patterns('',
url(r'^old/site/url.php开发者_如何转开发?someshit=(?P<id>\d+)',
'website.views.redirect_php'),
)
But I always get a 404 ..
I've also tried to escape it like this
urlpatterns = patterns('',
url(r'^old/site/url\.php\?someshit\=(?P<id>\d+)',
'website.views.redirect_php'),
)
No luck.
Any ideas ?
What you're doing does not work because GET parameters are not included in the string being matched by URLconf. (See What the URLconf searches against.)
To achieve the desired behaviour, you'll need to extract the GET parameter from within the view and redirect according.
urlpatterns = patterns('',
url(r'^old/site/url\.php$',
view='website.views.redirect_php',
name='redirect_php'
),
)
and in your view:
def redirect_php(request):
id = request.GET.get("somesheet", None)
if id == None:
# handle case where "somesheet=?" was not provided
else:
# handle redirects based on id
Give this a try:
urlpatterns = patterns('',
url(r'^old/site/url\.php?someshit=(?P<id>\d+)$',
'website.views.redirect_php', name='redirect_php'),
)
精彩评论