Store value request.is_localhost and pass request into all jinjas.

This commit is contained in:
voussoir 2021-02-25 18:52:25 -08:00
parent 27771f5763
commit 361795237c
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -78,7 +78,8 @@ site.route = decorate_and_route
@site.before_request @site.before_request
def before_request(): def before_request():
ip = request.remote_addr ip = request.remote_addr
if site.localhost_only and ip != '127.0.0.1': request.is_localhost = ip == '127.0.0.1'
if site.localhost_only and not request.is_localhost:
flask.abort(403) flask.abort(403)
gzip_minimum_size = 500 * bytestring.BYTE gzip_minimum_size = 500 * bytestring.BYTE
@ -213,6 +214,7 @@ def render_template(request, template_name, **kwargs):
response = flask.render_template( response = flask.render_template(
template_name, template_name,
request=request,
session=session, session=session,
theme=theme, theme=theme,
**kwargs, **kwargs,