librelist archives

« back to archive

Reusing code across multiple sites

Reusing code across multiple sites

From:
James Willson
Date:
2013-09-09 @ 21:53
Hi all,

I have a setup where I will have having around 50 sites using the same 
code, configured slightly differently. Rather than deploy the same code 
over and over again, duplicated across different folders and repositories,
is there any way to centralise the working code of the site, as some sort 
of library?

In Django I was able to find this: 
https://docs.djangoproject.com/en/dev/ref/contrib/sites/ but I can't seem 
to find or come up with a similar solution in flask.

Any help or advice would be much appreciated.

James

Re: [flask] Reusing code across multiple sites

From:
Ryan O'Donnell
Date:
2013-09-09 @ 22:00
I would immediately go to making your own "extension"
http://flask.pocoo.org/docs/extensiondev/

This should be perfectly valid for what you'd like to do, no?


On Mon, Sep 9, 2013 at 5:53 PM, James Willson <mail@employ.com> wrote:

> Hi all,
>
> I have a setup where I will have having around 50 sites using the same
> code, configured slightly differently. Rather than deploy the same code
> over and over again, duplicated across different folders and repositories,
> is there any way to centralise the working code of the site, as some sort
> of library?
>
> In Django I was able to find this:
> https://docs.djangoproject.com/en/dev/ref/contrib/sites/ but I can't seem
> to find or come up with a similar solution in flask.
>
> Any help or advice would be much appreciated.
>
> James
>
>

Re: [flask] Reusing code across multiple sites

From:
Matthew Hoopes
Date:
2013-09-09 @ 23:39
Hi James,

I very recently ran into a similar problem, and application dispatching did
exactly what I needed.

http://flask.pocoo.org/docs/patterns/appdispatch/

I was able to dispatch requests to separate apps. For me, it was based on
hostname - client1.domain.com got one instance of the app with a different
config, client2.domain.com got a different app, with their specific config.

The things I had to watch out for was doing anything on import (like doing
some sort of setup in __init__.py when a module was imported), or storing
anything on the class instead of an instance of the class.

Anyway, this worked/is working great for me - I was afraid I'd have to run
a different gunicorn per client, but this saved the day.


On Mon, Sep 9, 2013 at 5:53 PM, James Willson <mail@employ.com> wrote:

> Hi all,
>
> I have a setup where I will have having around 50 sites using the same
> code, configured slightly differently. Rather than deploy the same code
> over and over again, duplicated across different folders and repositories,
> is there any way to centralise the working code of the site, as some sort
> of library?
>
> In Django I was able to find this:
> https://docs.djangoproject.com/en/dev/ref/contrib/sites/ but I can't seem
> to find or come up with a similar solution in flask.
>
> Any help or advice would be much appreciated.
>
> James
>
>

Re: [flask] Reusing code across multiple sites

From:
Sjoerd Huisman | Congressus
Date:
2013-09-10 @ 07:07
could not decode message

Re: [flask] Reusing code across multiple sites

From:
James Zildjian
Date:
2013-09-10 @ 10:13
could not decode message

Re: [flask] Reusing code across multiple sites

From:
Matthew Hoopes
Date:
2013-09-10 @ 11:50
could not decode message

Re: [flask] Reusing code across multiple sites

From:
Sjoerd Huisman | Congressus
Date:
2013-09-10 @ 12:03
could not decode message

Re: [flask] Reusing code across multiple sites

From:
James Zildjian
Date:
2013-09-10 @ 14:14
could not decode message

Re: [flask] Reusing code across multiple sites

From:
Sjoerd Huisman | Congressus
Date:
2013-09-10 @ 14:35
could not decode message

Re: [flask] Reusing code across multiple sites

From:
James Zildjian
Date:
2013-09-10 @ 15:35
So build the logic to get the configuration for the hostname directly in
the main application and load a specialized configurations in a
@before_request handler?