Skip to content

Commit 0043f30

Browse files
committed
Use bytes BOUNDARY on django < 1.5
Django's encode_multipart was updated in django 1.5 to work internally with unicode and convert to bytes. In django >= 1.5 we therefore need to pass the BOUNDARY as unicode. In django < 1.5 we still need to pass it as bytes.
1 parent 78e4468 commit 0043f30

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

rest_framework/renderers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import copy
1212
import json
13+
import django
1314
from django import forms
1415
from django.core.exceptions import ImproperlyConfigured
1516
from django.http.multipartparser import parse_header
@@ -597,7 +598,7 @@ class MultiPartRenderer(BaseRenderer):
597598
media_type = 'multipart/form-data; boundary=BoUnDaRyStRiNg'
598599
format = 'multipart'
599600
charset = 'utf-8'
600-
BOUNDARY = 'BoUnDaRyStRiNg'
601+
BOUNDARY = 'BoUnDaRyStRiNg' if django.VERSION >= (1, 5) else b'BoUnDaRyStRiNg'
601602

602603
def render(self, data, accepted_media_type=None, renderer_context=None):
603604
return encode_multipart(self.BOUNDARY, data)

0 commit comments

Comments
 (0)