﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
413	[patch] FileField get_<fieldname>_url returns URL with backslashes on windows	Adam Endicott <leftwing17@…>	Adrian Holovaty	"I have a model with a !FileField: {{{ meta.FileField('file', upload_to='uploadDir'), }}}. On windows, when uploading the file, its path is saved in the database as 'uploadDir\filename' (with the backslash). This becomes a problem when using get_file_url() because the url then contains a backslash (in the form of: MEDIA_URL/uploadDir\filename)

The patch changes get_<fieldname>_url() behavior to replace all backslashes with forward slashes before returning (specifically, {{{ using .replace('\\', '/') }}}).

There was some discussion on #django about where to do the replace, here, or where the path is stored in the database, and we decided to do it just when retrieving a URL since the backslash is valid in a path until we start calling it a URL.

{{{
Index: django/core/meta/__init__.py
===================================================================
--- django/core/meta/__init__.py	(revision 547)
+++ django/core/meta/__init__.py	(working copy)
@@ -951,7 +951,7 @@
 def method_get_file_url(field, self):
     if getattr(self, field.name): # value is not blank
         import urlparse
-        return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.name))
+        return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.name)).replace('\\', '/')
     return ''
 
 def method_get_file_size(field, self):
}}}"	defect	closed	Core (Other)		normal	fixed	FileField url windows backslash		Unreviewed	1	0	0	0	0	0
