title: Redirecting to an external domain in Flask
body: <p>I'm writing a very simple flask app (a URL shortener) that should be able to redirect certain requests to other arbitrary domains. However, I am running into problems with the redirection. This stripped-down version, for example, doesn't work:</p>
  
  <pre><code>from app import app, db
  from flask import abort, redirect
  
  @app.route('/')
  def index():
      return "Hello, world"
  
  @app.route('/favicon.ico')
  def favicon():
      abort(404)
  
  @app.route('/&lt;slug&gt;')
  def redirect(slug):
      return redirect('http://google.com/')
  </code></pre>
  
  <p>Perhaps naively, I expected this to redirect to google.com, but instead the redirect seems to get "captured" by Flask, and it tries to route the redirected URL back through the redirect handler (e.g. <code>redirect(slug="http://google.com/")</code>) until it eats all the stack space through recursion and errors out. I can't  seem to figure out why this would happen, or how to work around it, but I'd really appreciate a pointer in the right direction.</p>