You are here: Home / What do you need? / Help and documentation / Plone Info / URL encoding in a script for Plone

URL encoding in a script for Plone

by Darrell Kingsley last modified Mar 13, 2014 01:03 PM
Sometimes you might need a bit of URL encoding in a python script, for example while writing an URL in a text email which is then auto-translated into a link by the mail client. It's not obvious how to do it, but it is easy.

First thing you think of is python's urllib or urlencode, but security means you can't import either of these. That would mean an external method, which is a bit heavy duty really.

Luckily, we can just

from Products.PythonScripts.standard import url_quote

That works just fine.

If you want + instead of %20 for spaces use

from Products.PythonScripts.standard import url_quote_plus

Then obviously it's just

url_quote( url with spaces)


url_quote_plus( url with spaces)

Everything in the garden is rosy once more.