59 | | new_url[1] = new_url[1] + '/' |
60 | | if settings.DEBUG and request.method == 'POST': |
61 | | raise RuntimeError, ("" |
62 | | "You called this URL via POST, but the URL doesn't end " |
63 | | "in a slash and you have APPEND_SLASH set. Django can't " |
64 | | "redirect to the slash URL while maintaining POST data. " |
65 | | "Change your form to point to %s%s (note the trailing " |
66 | | "slash), or set APPEND_SLASH=False in your Django " |
67 | | "settings.") % (new_url[0], new_url[1]) |
| 59 | # Check if slash ending path exists |
| 60 | try: |
| 61 | urlresolvers.resolve("%s/" % request.path_info) |
| 62 | except urlresolvers.Resolver404: |
| 63 | pass |
| 64 | else: |
| 65 | new_url[1] = new_url[1] + '/' |
| 66 | if settings.DEBUG and request.method == 'POST': |
| 67 | raise RuntimeError, ("You called this URL via POST, " |
| 68 | "but the URL doesn't end in a slash and you have " |
| 69 | "APPEND_SLASH set. Django can't redirect to the slash " |
| 70 | "URL while maintaining POST data. Change your form to " |
| 71 | "point to %s%s (note the trailing slash), or set " |
| 72 | "APPEND_SLASH=False in your Django " |
| 73 | "settings.") % (new_url[0], new_url[1]) |
76 | | if new_url[0]: |
77 | | newurl = "%s://%s%s" % ( |
78 | | request.is_secure() and 'https' or 'http', |
79 | | new_url[0], urlquote(new_url[1])) |
80 | | else: |
81 | | newurl = urlquote(new_url[1]) |
82 | | if request.GET: |
83 | | newurl += '?' + request.META['QUERY_STRING'] |
84 | | return http.HttpResponsePermanentRedirect(newurl) |
| 81 | newurl = urlquote(new_url[1]) |
| 82 | if request.GET: |
| 83 | newurl += '?' + request.META['QUERY_STRING'] |
| 84 | return http.HttpResponsePermanentRedirect(newurl) |