Python werkzeug.urls.url_parse() Examples
The following are 30
code examples of werkzeug.urls.url_parse().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
werkzeug.urls
, or try the search function
.
Example #1
Source File: helpers.py From api-pycon2014 with MIT License | 6 votes |
def match_url(url, method=None): appctx = _app_ctx_stack.top reqctx = _request_ctx_stack.top if appctx is None: raise RuntimeError('Attempted to match a URL without the ' 'application context being pushed. This has to be ' 'executed when application context is available.') if reqctx is not None: url_adapter = reqctx.url_adapter else: url_adapter = appctx.url_adapter if url_adapter is None: raise RuntimeError('Application was not able to create a URL ' 'adapter for request independent URL matching. ' 'You might be able to fix this by setting ' 'the SERVER_NAME config variable.') parsed_url = url_parse(url) if parsed_url.netloc is not '' and \ parsed_url.netloc != url_adapter.server_name: raise NotFound() return url_adapter.match(parsed_url.path, method)
Example #2
Source File: routes.py From FlaskQuickStart with Apache License 2.0 | 6 votes |
def login(): # 判断当前用户是否验证,如果通过的话返回首页 if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() # user = None if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() # print("user", user) if user is None or not user.check_password(form.password.data): flash('无效的用户名或密码') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) # 此时的next_page记录的是跳转至登录页面是的地址 next_page = request.args.get('next') # 如果next_page记录的地址不存在那么就返回首页 if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') # 综上,登录后要么重定向至跳转前的页面,要么跳转至首页 return redirect(next_page) # 一定要有返回体,原文作者未提及,否则用户未登陆时候会报错 return render_template('login.html', title='登录', form=form)
Example #3
Source File: webapp.py From dash_on_flask with MIT License | 6 votes |
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): error = 'Invalid username or password' return render_template('login.html', form=form, error=error) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
Example #4
Source File: helpers.py From api-pycon2015 with MIT License | 6 votes |
def match_url(url, method=None): appctx = _app_ctx_stack.top reqctx = _request_ctx_stack.top if appctx is None: raise RuntimeError('Attempted to match a URL without the ' 'application context being pushed. This has to be ' 'executed when application context is available.') if reqctx is not None: url_adapter = reqctx.url_adapter else: url_adapter = appctx.url_adapter if url_adapter is None: raise RuntimeError('Application was not able to create a URL ' 'adapter for request independent URL matching. ' 'You might be able to fix this by setting ' 'the SERVER_NAME config variable.') parsed_url = url_parse(url) if parsed_url.netloc is not '' and \ parsed_url.netloc != url_adapter.server_name: raise NotFound() return url_adapter.match(parsed_url.path, method)
Example #5
Source File: test_query.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_to_url_with_specified_url(self, app): kwargs = { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': 2, } search_query = search.search_for(FakeSearch, **kwargs) with app.test_request_context('/an_url'): url = search_query.to_url('/another_url') parsed_url = url_parse(url) qs = url_decode(parsed_url.query) assert parsed_url.path == '/another_url' assert_json_equal(multi_to_dict(qs), { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': '2', })
Example #6
Source File: test_query.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_to_url_with_none(self, app): kwargs = { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': 2, } search_query = search.search_for(FakeSearch, **kwargs) with app.test_request_context('/an_url'): url = search_query.to_url(tag=None, other='value', replace=True) parsed_url = url_parse(url) qs = url_decode(parsed_url.query) assert parsed_url.path == '/an_url' assert_json_equal(multi_to_dict(qs), { 'q': 'test', 'other': 'value', })
Example #7
Source File: test_query.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_to_url_with_override_and_replace(self, app): kwargs = { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': 2, } search_query = search.search_for(FakeSearch, **kwargs) with app.test_request_context('/an_url'): url = search_query.to_url(tag='tag3', other='value', replace=True) parsed_url = url_parse(url) qs = url_decode(parsed_url.query) assert parsed_url.path == '/an_url' assert_json_equal(multi_to_dict(qs), { 'q': 'test', 'tag': 'tag3', 'other': 'value', })
Example #8
Source File: test_query.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_to_url_with_override(self, app): kwargs = { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': 2, } search_query = search.search_for(FakeSearch, **kwargs) with app.test_request_context('/an_url'): url = search_query.to_url(tag='tag3', other='value') parsed_url = url_parse(url) qs = url_decode(parsed_url.query) assert parsed_url.path == '/an_url' assert_json_equal(multi_to_dict(qs), { 'q': 'test', 'tag': ['tag1', 'tag2', 'tag3'], 'other': 'value', })
Example #9
Source File: test_query.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_to_url(self, app): kwargs = { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': 2, 'facets': True, } search_query = search.search_for(FakeSearch, **kwargs) with app.test_request_context('/an_url'): url = search_query.to_url() parsed_url = url_parse(url) qs = url_decode(parsed_url.query) assert parsed_url.path == '/an_url' assert_json_equal(multi_to_dict(qs), { 'q': 'test', 'tag': ['tag1', 'tag2'], 'page': '2', })
Example #10
Source File: urls.py From Flask with Apache License 2.0 | 6 votes |
def test_url_attributes(self): rv = urls.url_parse('http://foo%3a:bar%3a@[::1]:80/123?x=y#frag') self.assert_strict_equal(rv.scheme, 'http') self.assert_strict_equal(rv.auth, 'foo%3a:bar%3a') self.assert_strict_equal(rv.username, u'foo:') self.assert_strict_equal(rv.password, u'bar:') self.assert_strict_equal(rv.raw_username, 'foo%3a') self.assert_strict_equal(rv.raw_password, 'bar%3a') self.assert_strict_equal(rv.host, '::1') self.assert_equal(rv.port, 80) self.assert_strict_equal(rv.path, '/123') self.assert_strict_equal(rv.query, 'x=y') self.assert_strict_equal(rv.fragment, 'frag') rv = urls.url_parse(u'http://\N{SNOWMAN}.com/') self.assert_strict_equal(rv.host, u'\N{SNOWMAN}.com') self.assert_strict_equal(rv.ascii_host, 'xn--n3h.com')
Example #11
Source File: http.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 6 votes |
def __call__(self, environ, start_response): def start_wrapped(status, headers): referer = environ.get('HTTP_REFERER', '') parsed = urls.url_parse(referer) debug = parsed.query.count('debug') >= 1 new_headers = [] unwanted_keys = ['Last-Modified'] if debug: new_headers = [('Cache-Control', 'no-cache')] unwanted_keys += ['Expires', 'Etag', 'Cache-Control'] for k, v in headers: if k not in unwanted_keys: new_headers.append((k, v)) start_response(status, new_headers) return self.app(environ, start_wrapped)
Example #12
Source File: urls.py From Flask with Apache License 2.0 | 6 votes |
def test_url_attributes(self): rv = urls.url_parse('http://foo%3a:bar%3a@[::1]:80/123?x=y#frag') self.assert_strict_equal(rv.scheme, 'http') self.assert_strict_equal(rv.auth, 'foo%3a:bar%3a') self.assert_strict_equal(rv.username, u'foo:') self.assert_strict_equal(rv.password, u'bar:') self.assert_strict_equal(rv.raw_username, 'foo%3a') self.assert_strict_equal(rv.raw_password, 'bar%3a') self.assert_strict_equal(rv.host, '::1') self.assert_equal(rv.port, 80) self.assert_strict_equal(rv.path, '/123') self.assert_strict_equal(rv.query, 'x=y') self.assert_strict_equal(rv.fragment, 'frag') rv = urls.url_parse(u'http://\N{SNOWMAN}.com/') self.assert_strict_equal(rv.host, u'\N{SNOWMAN}.com') self.assert_strict_equal(rv.ascii_host, 'xn--n3h.com')
Example #13
Source File: routes.py From code-jam-5 with MIT License | 5 votes |
def login(): """ Log in to an account """ if current_user.is_authenticated: return redirect(url_for("index")) form = LoginForm() if form.validate(): print('success') if form.validate_on_submit(): print("Execute validate") user = User.query.filter_by(name=form.username.data).first() if user is None or not user.check_password(form.password.data): flash("Invalid username or password", "error") return redirect(url_for("login")) login_user(user) flash("Login successful", "success") next_page = request.args.get("next") if not next_page or url_parse(next_page).netloc != "": next_page = url_for("index") return redirect(next_page) return render_template("login.html", title="Sign In", form=form) ''' if request.method == "GET": return render_template("login.html") elif request.method == "POST": username = request.form["username"] password = request.form["password"] user = User.query.filter_by(name=username).first() if user and user.check_password(password): login_user(user) flash("Login successful", "success") return redirect(url_for("index")) else: flash("Incorrect username or password", "danger") return render_template("login.html") '''
Example #14
Source File: testing.py From data with GNU General Public License v3.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #15
Source File: serving.py From data with GNU General Public License v3.0 | 5 votes |
def make_environ(self): request_url = url_parse(self.path) def shutdown_server(): self.server.shutdown_signal = True url_scheme = self.server.ssl_context is None and 'http' or 'https' path_info = url_unquote(request_url.path) environ = { 'wsgi.version': (1, 0), 'wsgi.url_scheme': url_scheme, 'wsgi.input': self.rfile, 'wsgi.errors': sys.stderr, 'wsgi.multithread': self.server.multithread, 'wsgi.multiprocess': self.server.multiprocess, 'wsgi.run_once': False, 'werkzeug.server.shutdown': shutdown_server, 'SERVER_SOFTWARE': self.server_version, 'REQUEST_METHOD': self.command, 'SCRIPT_NAME': '', 'PATH_INFO': wsgi_encoding_dance(path_info), 'QUERY_STRING': wsgi_encoding_dance(request_url.query), 'CONTENT_TYPE': self.headers.get('Content-Type', ''), 'CONTENT_LENGTH': self.headers.get('Content-Length', ''), 'REMOTE_ADDR': self.client_address[0], 'REMOTE_PORT': self.client_address[1], 'SERVER_NAME': self.server.server_address[0], 'SERVER_PORT': str(self.server.server_address[1]), 'SERVER_PROTOCOL': self.request_version } for key, value in self.headers.items(): key = 'HTTP_' + key.upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value if request_url.netloc: environ['HTTP_HOST'] = request_url.netloc return environ
Example #16
Source File: testing.py From Flask with Apache License 2.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #17
Source File: urls.py From Flask with Apache License 2.0 | 5 votes |
def test_replace(self): url = urls.url_parse('http://de.wikipedia.org/wiki/Troll') self.assert_strict_equal(url.replace(query='foo=bar'), urls.url_parse('http://de.wikipedia.org/wiki/Troll?foo=bar')) self.assert_strict_equal(url.replace(scheme='https'), urls.url_parse('https://de.wikipedia.org/wiki/Troll'))
Example #18
Source File: urls.py From Flask with Apache License 2.0 | 5 votes |
def test_url_attributes_bytes(self): rv = urls.url_parse(b'http://foo%3a:bar%3a@[::1]:80/123?x=y#frag') self.assert_strict_equal(rv.scheme, b'http') self.assert_strict_equal(rv.auth, b'foo%3a:bar%3a') self.assert_strict_equal(rv.username, u'foo:') self.assert_strict_equal(rv.password, u'bar:') self.assert_strict_equal(rv.raw_username, b'foo%3a') self.assert_strict_equal(rv.raw_password, b'bar%3a') self.assert_strict_equal(rv.host, b'::1') self.assert_equal(rv.port, 80) self.assert_strict_equal(rv.path, b'/123') self.assert_strict_equal(rv.query, b'x=y') self.assert_strict_equal(rv.fragment, b'frag')
Example #19
Source File: serving.py From data with GNU General Public License v3.0 | 5 votes |
def make_environ(self): request_url = url_parse(self.path) def shutdown_server(): self.server.shutdown_signal = True url_scheme = self.server.ssl_context is None and 'http' or 'https' path_info = url_unquote(request_url.path) environ = { 'wsgi.version': (1, 0), 'wsgi.url_scheme': url_scheme, 'wsgi.input': self.rfile, 'wsgi.errors': sys.stderr, 'wsgi.multithread': self.server.multithread, 'wsgi.multiprocess': self.server.multiprocess, 'wsgi.run_once': False, 'werkzeug.server.shutdown': shutdown_server, 'SERVER_SOFTWARE': self.server_version, 'REQUEST_METHOD': self.command, 'SCRIPT_NAME': '', 'PATH_INFO': wsgi_encoding_dance(path_info), 'QUERY_STRING': wsgi_encoding_dance(request_url.query), 'CONTENT_TYPE': self.headers.get('Content-Type', ''), 'CONTENT_LENGTH': self.headers.get('Content-Length', ''), 'REMOTE_ADDR': self.client_address[0], 'REMOTE_PORT': self.client_address[1], 'SERVER_NAME': self.server.server_address[0], 'SERVER_PORT': str(self.server.server_address[1]), 'SERVER_PROTOCOL': self.request_version } for key, value in self.headers.items(): key = 'HTTP_' + key.upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value if request_url.netloc: environ['HTTP_HOST'] = request_url.netloc return environ
Example #20
Source File: urls.py From Flask with Apache License 2.0 | 5 votes |
def test_replace(self): url = urls.url_parse('http://de.wikipedia.org/wiki/Troll') self.assert_strict_equal(url.replace(query='foo=bar'), urls.url_parse('http://de.wikipedia.org/wiki/Troll?foo=bar')) self.assert_strict_equal(url.replace(scheme='https'), urls.url_parse('https://de.wikipedia.org/wiki/Troll'))
Example #21
Source File: urls.py From Flask with Apache License 2.0 | 5 votes |
def test_url_attributes_bytes(self): rv = urls.url_parse(b'http://foo%3a:bar%3a@[::1]:80/123?x=y#frag') self.assert_strict_equal(rv.scheme, b'http') self.assert_strict_equal(rv.auth, b'foo%3a:bar%3a') self.assert_strict_equal(rv.username, u'foo:') self.assert_strict_equal(rv.password, u'bar:') self.assert_strict_equal(rv.raw_username, b'foo%3a') self.assert_strict_equal(rv.raw_password, b'bar%3a') self.assert_strict_equal(rv.host, b'::1') self.assert_equal(rv.port, 80) self.assert_strict_equal(rv.path, b'/123') self.assert_strict_equal(rv.query, b'x=y') self.assert_strict_equal(rv.fragment, b'frag')
Example #22
Source File: serving.py From data with GNU General Public License v3.0 | 5 votes |
def make_environ(self): request_url = url_parse(self.path) def shutdown_server(): self.server.shutdown_signal = True url_scheme = self.server.ssl_context is None and 'http' or 'https' path_info = url_unquote(request_url.path) environ = { 'wsgi.version': (1, 0), 'wsgi.url_scheme': url_scheme, 'wsgi.input': self.rfile, 'wsgi.errors': sys.stderr, 'wsgi.multithread': self.server.multithread, 'wsgi.multiprocess': self.server.multiprocess, 'wsgi.run_once': False, 'werkzeug.server.shutdown': shutdown_server, 'SERVER_SOFTWARE': self.server_version, 'REQUEST_METHOD': self.command, 'SCRIPT_NAME': '', 'PATH_INFO': wsgi_encoding_dance(path_info), 'QUERY_STRING': wsgi_encoding_dance(request_url.query), 'CONTENT_TYPE': self.headers.get('Content-Type', ''), 'CONTENT_LENGTH': self.headers.get('Content-Length', ''), 'REMOTE_ADDR': self.client_address[0], 'REMOTE_PORT': self.client_address[1], 'SERVER_NAME': self.server.server_address[0], 'SERVER_PORT': str(self.server.server_address[1]), 'SERVER_PROTOCOL': self.request_version } for key, value in self.headers.items(): key = 'HTTP_' + key.upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value if request_url.netloc: environ['HTTP_HOST'] = request_url.netloc return environ
Example #23
Source File: serving.py From data with GNU General Public License v3.0 | 5 votes |
def make_environ(self): request_url = url_parse(self.path) def shutdown_server(): self.server.shutdown_signal = True url_scheme = self.server.ssl_context is None and 'http' or 'https' path_info = url_unquote(request_url.path) environ = { 'wsgi.version': (1, 0), 'wsgi.url_scheme': url_scheme, 'wsgi.input': self.rfile, 'wsgi.errors': sys.stderr, 'wsgi.multithread': self.server.multithread, 'wsgi.multiprocess': self.server.multiprocess, 'wsgi.run_once': False, 'werkzeug.server.shutdown': shutdown_server, 'SERVER_SOFTWARE': self.server_version, 'REQUEST_METHOD': self.command, 'SCRIPT_NAME': '', 'PATH_INFO': wsgi_encoding_dance(path_info), 'QUERY_STRING': wsgi_encoding_dance(request_url.query), 'CONTENT_TYPE': self.headers.get('Content-Type', ''), 'CONTENT_LENGTH': self.headers.get('Content-Length', ''), 'REMOTE_ADDR': self.client_address[0], 'REMOTE_PORT': self.client_address[1], 'SERVER_NAME': self.server.server_address[0], 'SERVER_PORT': str(self.server.server_address[1]), 'SERVER_PROTOCOL': self.request_version } for key, value in self.headers.items(): key = 'HTTP_' + key.upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value if request_url.netloc: environ['HTTP_HOST'] = request_url.netloc return environ
Example #24
Source File: testing.py From data with GNU General Public License v3.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #25
Source File: testing.py From appengine-try-python-flask with Apache License 2.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #26
Source File: testing.py From arithmancer with Apache License 2.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #27
Source File: serving.py From syntheticmass with Apache License 2.0 | 5 votes |
def make_environ(self): request_url = url_parse(self.path) def shutdown_server(): self.server.shutdown_signal = True url_scheme = self.server.ssl_context is None and 'http' or 'https' path_info = url_unquote(request_url.path) environ = { 'wsgi.version': (1, 0), 'wsgi.url_scheme': url_scheme, 'wsgi.input': self.rfile, 'wsgi.errors': sys.stderr, 'wsgi.multithread': self.server.multithread, 'wsgi.multiprocess': self.server.multiprocess, 'wsgi.run_once': False, 'werkzeug.server.shutdown': shutdown_server, 'SERVER_SOFTWARE': self.server_version, 'REQUEST_METHOD': self.command, 'SCRIPT_NAME': '', 'PATH_INFO': wsgi_encoding_dance(path_info), 'QUERY_STRING': wsgi_encoding_dance(request_url.query), 'CONTENT_TYPE': self.headers.get('Content-Type', ''), 'CONTENT_LENGTH': self.headers.get('Content-Length', ''), 'REMOTE_ADDR': self.client_address[0], 'REMOTE_PORT': self.client_address[1], 'SERVER_NAME': self.server.server_address[0], 'SERVER_PORT': str(self.server.server_address[1]), 'SERVER_PROTOCOL': self.request_version } for key, value in self.headers.items(): key = 'HTTP_' + key.upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value if request_url.netloc: environ['HTTP_HOST'] = request_url.netloc return environ
Example #28
Source File: testing.py From syntheticmass with Apache License 2.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #29
Source File: testing.py From cloud-playground with Apache License 2.0 | 5 votes |
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): """Creates a new test builder with some application defaults thrown in.""" http_host = app.config.get('SERVER_NAME') app_root = app.config.get('APPLICATION_ROOT') if base_url is None: url = url_parse(path) base_url = 'http://%s/' % (url.netloc or http_host or 'localhost') if app_root: base_url += app_root.lstrip('/') if url.netloc: path = url.path return EnvironBuilder(path, base_url, *args, **kwargs)
Example #30
Source File: routes.py From tutorial-flask with Apache License 2.0 | 5 votes |
def login(): if current_user.is_authenticated: return redirect(url_for('public.index')) form = LoginForm() if form.validate_on_submit(): user = User.get_by_email(form.email.data) if user is not None and user.check_password(form.password.data): login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('public.index') return redirect(next_page) return render_template('auth/login_form.html', form=form)