[Answered ]-What is "dictionary-style string formatting" used in Django RedirectView url

1👍

That refers to a specific way to use the % string-formatting operator:

print "Hello, %(thing)s!" % {"thing": "world"}

prints “Hello, world!”

You want to use a redirect URL like ‘/%(school_slug)s/%(menu_type_slug)s/print/’, the redirect view will receive a kwargs dictionary with keys ‘school_slug’ and ‘menu_type_slug’ and use it as argument for %.

1👍

It refers to formatting strings by interpolating entries from a dictionary into a string:

>>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
>>> "%(pwd)s" % params                                    1
'secret'

If I interpret the Django documentation correctly, you can only use this to substitute URL query parameters, which are of the form kwd=value. The components of the path are not available for substitution.

👤Barmar

Leave a comment