Answer the question
In order to leave comments, you need to log in
How to make multiple websites in one Flask application?
Tell me how you can make a lot of different sites, with almost the same functionality, but completely different design on one application written using Flask?
Those. it is written, something like a CMS and is used for about 10 sites, on one VPS.
UPD: So far I'm doing this: I took the request manager from the Flask documentation (there is one there).
The script scans the underlying directories, and if it finds a config in them, then for each directory it creates an application instance with the settings specified in the file, while specifying the variables: root_path, instance_path, template_folder, static_folder.
Further, the list of instances is transferred to the dispatcher, which selects by the host parameter in the request which application to transfer the request to next.
Answer the question
In order to leave comments, you need to log in
I had a similar task.
Solved it like this:
@app.before_request
def before_request():
sitename = db = ""
if request.headers['Host'] in 'www.example1.com':
sitename = 'example1.com'
db = 'example1_com'
elif request.headers['Host'] in 'www.example2.com':
sitename = 'example2.com'
db = 'example2_com'
else:
sitename = 'test.com'
db = 'test_com'
# И т.д.
app.jinja_env.globals['sitename'] = sitename
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question