Comments (4)
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.
from django-rest-framework-csv.
class MyCustomRenderer (CSVRenderer): writer_opts = dict( delimiter=';', )
This could go in the readme 🙂
from django-rest-framework-csv.
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', ';')
from django-rest-framework-csv.
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',
from django-rest-framework-csv.
Related Issues (20)
- Assertion doomed to fail with different expected results? HOT 1
- Mutable dict used as default arg? HOT 1
- CSVStreamingRenderer Example HOT 2
- Generator objects cannot be passed into CSVStreamingRenderer
- Document data.header
- Field Order / Headers from the Serializer HOT 3
- response['Content-Type'] not set HOT 1
- Expose Sorting Function HOT 1
- Potential compatibility issue / style improvement HOT 1
- newline handling in restframework csv HOT 4
- NewLine Header
- Releases potentially causing the project to appear unmaintained HOT 1
- Add support Django 3.2 HOT 1
- Bug: after data has been flattened, and header has been explicitely set, the CSV output is missing the flattened data
- Suggestion of mixin
- Document CSVParser usage
- The fields in the CSV file are not the same as those defined in my serializer
- handle the BOM character using utf-8-sig
- Is this package still maintained? HOT 1
- django 'user' object has no attribute 'active' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-framework-csv.