Code Monkey home page Code Monkey logo

Comments (4)

mjumbewu avatar mjumbewu commented on June 27, 2024 2

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.

Crocmagnon avatar Crocmagnon commented on June 27, 2024 2
class MyCustomRenderer (CSVRenderer):
    writer_opts = dict(
        delimiter=';',
    )

This could go in the readme 🙂

from django-rest-framework-csv.

ManPython avatar ManPython commented on June 27, 2024

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.

ManPython avatar ManPython commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.