tomchristie/django-rest-framework — Issue #106: Change of the set_script_prefix
Author: Natim
Created: 2012-01-03 13:43:34+00:00
State: open

djangorestframework.views change the script_prefix.

But in my case, the orig_prefix is already right and the concatenation of orig_prefix and prefix make it looks like :

`http://localhost:8000http://localhost:8000/api/` instead of `http://localhost:8000/api/`

Here is my patch but I am not quite sure in which case the orign_prefix can be wrong.

diff -r 06444072471f djangorestframework/views.py
--- a/djangorestframework/views.py	Tue Jan 03 02:00:06 2012 -0800
+++ b/djangorestframework/views.py	Tue Jan 03 14:32:03 2012 +0100
@@ -109,7 +109,8 @@
# Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
orig_prefix = get_script_prefix()
prefix = '%s://%s' % (request.is_secure() and 'https' or 'http', request.get_host())
- set_script_prefix(prefix + orig_prefix)
+ if not orig_prefix.startswith('http'):
+ set_script_prefix(prefix + orig_prefix)

try:
self.initial(request, *args, **kwargs)