Home > Software engineering >  django: pass json string to url as parameter
django: pass json string to url as parameter

Time:04-09

How can I define a regex for pass json string to url as parameter in django framework?

Now I use (?P<query>\w ) but it doesn't work because json string is a entire string made with different words.

Using the URLconf defined in giustiziasite.urls, Django tried these URL patterns, in this order:
    ^pygiustizia/ ^exportcsv-show-results/q/(?P<query>\w )$ [name='exportcsv-show-results']
    admin/

The current path, pygiustizia/exportcsv-show-results/q/{"query": {"bool": {"must": [], "should": []}}, "_source": ["annoruolo", "annosentenza", "codiceoggetto"]}, didn’t match any of these.

CodePudding user response:

You can't pass parameters like this in url

Please use an encoded string instead of these or use the slug to pass different parameters as kwargs

path('your-url/<slug:slug1>/<slug:slug2>/', YourView.as_view(), name='your_view')

CodePudding user response:

For accept all characters and words I use this: (?P<query>.*)

Note .* means all characters including special characters

Thus I can pass to url this json string:

{"query": {"bool": {"must": [], "should": []}}, "_source": ["annoruolo", "annosentenza", "codiceoggetto"]}
  • Related