Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added helper method redirect_url_for #958

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask/__init__.py
Expand Up @@ -22,7 +22,7 @@
from .config import Config
from .helpers import url_for, flash, send_file, send_from_directory, \
get_flashed_messages, get_template_attribute, make_response, safe_join, \
stream_with_context
stream_with_context, redirect_url_for
from .globals import current_app, g, request, session, _request_ctx_stack, \
_app_ctx_stack
from .ctx import has_request_context, has_app_context, \
Expand Down
7 changes: 7 additions & 0 deletions flask/helpers.py
Expand Up @@ -27,6 +27,7 @@

from werkzeug.datastructures import Headers
from werkzeug.exceptions import NotFound
from werkzeug.utils import redirect

# this was moved in 0.7
try:
Expand Down Expand Up @@ -183,6 +184,12 @@ def index():
return current_app.make_response(args)


def redirect_url_for(endpoint, **values):
"""Return a response object (a WSGI application) that, if called,
redirects the client to the given endpoit."""
return redirect(url_for(endpoint, **values))


def url_for(endpoint, **values):
"""Generates a URL to the given endpoint with the method provided.

Expand Down
11 changes: 11 additions & 0 deletions flask/testsuite/helpers.py
Expand Up @@ -534,6 +534,17 @@ def post(self):
self.assert_equal(flask.url_for('myview', _method='POST'),
'/myview/create')

def test_redirect_url_for(self):
app = flask.Flask(__name__)
@app.route('/')
def index():
return '42'
with app.test_request_context():
redir = flask.redirect_url_for("index")
self.assert_equal("/", redir.location)
self.assert_equal(302, redir.status_code)



class NoImportsTestCase(FlaskTestCase):
"""Test Flasks are created without import.
Expand Down