Search code examples
pythoncherrypy

Have CherryPy "submit" button launch external web page


I have a very simple CherryPy web form that takes a user-submitted string. What I want is to take that string, build a URL from it, and launch an external web page. I have it so the URL is built -- I just don't now to actually open the URL on submit. Thoughts?

from cherrypy import expose
from jira.client import JIRA

class Redirector:
    @expose
    def index(self):
        return '''<html>
                  <body>
                  <form action="redirect">
                      <input name="url" />
                      <input type="submit" />
                  </form>
                  </body>
                  </html>'''

    @expose
    def redirect(self, url):
        return url


if __name__ == "__main__":
    from cherrypy import quickstart
    quickstart(Redirector())

Solution

  • Try this...

    @expose
    def redirect(self, url):
        raise cherrypy.HTTPRedirect(url)
    

    Hope this helps!