Skip to content

Instantly share code, notes, and snippets.

@gordonjcp
Created November 6, 2019 14:27
Show Gist options
  • Save gordonjcp/d01b2093ae2196f8996c414987d381e2 to your computer and use it in GitHub Desktop.
Save gordonjcp/d01b2093ae2196f8996c414987d381e2 to your computer and use it in GitHub Desktop.
from flask import Flask, Blueprint, g
### site blueprint
site = Blueprint('site', __name__)
@site.url_value_preprocessor
def get_site(endpoint, values):
# grab all subdomains, as an example
site = values.pop('site_subdomain')
g.site = site
@site.route('/')
def index():
return 'This site has the subdomain %s.' % g.site
### post blueprint
post = Blueprint('post', __name__)
@post.route('/')
def index():
if 'site' in g:
return 'This is a view in the post blueprint, subdomain %s' % g.site
else:
return 'This is a view in the post blueprint, with no subdomain (which shouldn\'t really happen)'
@post.route('/example')
def example():
return 'This is an example post'
### flask app
app = Flask(__name__)
app.config['SERVER_NAME']='test.inet:5000'
app.register_blueprint(site, subdomain='<site_subdomain>')
app.register_blueprint(post, url_prefix='/post')
@app.route('/')
def index():
return 'This is the main site with no subdomain'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment