Open ManPython opened 7 years ago
In parsers.py we have line 39
delimiter = parser_context.get('delimiter', ',')
changed to
delimiter = parser_context.get('delimiter', ';')
but no reaction
Soo..I sugesting maybe to made 2 options
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
'rest_framework_csv.parsers.CSVParser',
'rest_framework_csv.parsers.CSVParser2',
)
rest_framework_csv.parsers.CSVParser with ('delimiter', ',') rest_framework_csv.parsers.CSVParser2 with ('delimiter', ';')
You're looking to change the CSV output to have ;
as the delimeter, yes? That would be controlled in the renderer rather than the parser.
To create a renderer that uses semicolons, you could do something like:
class MyCustomRenderer (CSVRenderer):
writer_opts = dict(
delimiter=';',
)
Then you could use that renderer on a per-view basis, or set it in the DEFAULT_RENDERER_CLASSES
setting.
Yes, thank you for correct way. For future, on Python27
class CSVRenderer2 (CSVRenderer): writer_opts = dict( delimiter= str(';'), )
coz
Exception Value: "delimiter" must be string, not unicode
By my opinion this should be done as:
response = Response(data, status=None, template_name=None, headers=None, content_type='text/csv', content_disposition = 'attachment', filename ='my_filename', delimeter =';')
in case that format = csv
format = self.request.query_params.get('format', None) if format == 'csv':
by default if
REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.BrowsableAPIRenderer', 'rest_framework_csv.renderers.CSVRenderer',
class MyCustomRenderer (CSVRenderer): writer_opts = dict( delimiter=';', )
This could go in the readme 🙂
How we can easy change comma separator from ',' to ';' in .csv file?