Note: prior to posting I already searched for csv regex. The best regex I found for csv so far can be found in the answer here.
I would like to create a custom path converter for handling a csv e.g. something like:
register_converter(CSVConverter, 'csv')
urlpatterns = [
...
path('csv/<csv:list_of_values>/', views.csv_view, name='csv_view'),
...
]
where each value of list_of_values
is a string that does not need to be wrapped in quotes e.g.
http://localhost:8000/csv/value1,value2,value3/
I tried the following:
class CSVConverter:
# see https://stackoverflow.com/a/48806378/5623899
regex = "(?:,|\n|^)(\"(?:(?:\"\")*[^\"]*)*\"|[^\",\n]*|(?:\n|$))"
def to_python(self, value):
return value.split(',')
def to_url(self, value):
return ','.join(value)
but this doesn't work...