K
K
Konstantin2015-02-13 15:55:36
Flask
Konstantin, 2015-02-13 15:55:36

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

2 answer(s)
P
pcdesign, 2015-02-13
@Lord_Prizrak

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

Well, that is, the resolution was at the @app.before_request level.

E
evgenusov, 2015-02-13
@evgenusov

So are there patterns? Just make a variable with paths to different templates and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question