Hey all, Searched for a little while, but wasn't really able to find an answer to this. Is there a way to use flask with multiple domains (not subdomains)? It would be nice to say have domain 'siteone.com' route to '/siteone' and 'sitetwo.com' that routes to '/sitetwo'. Any help would be appreciated! Cheers, Cory
I was pondering the same thing myself. My idea was to serve multiple
websites from one python interpreter to make better utilization of CPU/RAM.
I was just testing this out yesterday. Of course you'll probably want to
retrieve the pages from a database table but I hope this helps.
The first step is to setup your DNS. The easiest way is to edit your
/etc/hosts file:
# add this entry
127.0.0.1 localhost www.a.com www.b.com
# your mutisite.py, if you're on OS X or *nix you have to run it as root
because its a port below 1000 (sudo python multisite.py)
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
# Return different results depending on the host
url = split_url(request.url)
if "www.a.com" == url['domain']:
return "<h1>You are visiting www.a.com</h1><p>Here's your URL " +
request.url + "</p>"
else:
return "<h1>You are not visiting www.a.com</h1><p>Here's your URL "
+ request.url + "</p>"
def split_url(url):
"Returns the full URL in two parts, the domain, and the path"
url = url.split('/', 3)
return {'domain': url[2], 'path': url[3]}
# run webserver only if this script is not imported
if __name__ == '__main__':
app.debug = True
app.run(port=80, host="0.0.0.0")
I decided to do this as a werkzeug app after my testing. I can't remember
why though!
Chris
On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote:
> Hey all,
>
>
>
> Searched for a little while, but wasn’t really able to find an answer to
> this. Is there a way to use flask with multiple domains (not subdomains)?
> It would be nice to say have domain ‘siteone.com’ route to ‘/siteone’ and
> ‘sitetwo.com’ that routes to ‘/sitetwo’.
>
>
>
> Any help would be appreciated!
>
>
>
> Cheers,
>
> Cory
>
If you want to run multiple applications in the same interpreter, take a look at: http://flask.pocoo.org/docs/patterns/appdispatch/ Note that the builtin web server on Flask [app.run(...)] is only intended for development use. If for some reason you are running the development server on a publicly accessible URL (e.g. temporary review), then be sure app.debug == False. Otherwise, anyone who triggers the debugger can run code on your server using the Werkzeug debugger's (awesome for development) interactive features. -Ron On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule <guitarift@gmail.com> wrote: > I was pondering the same thing myself. My idea was to serve multiple > websites from one python interpreter to make better utilization of CPU/RAM. > I was just testing this out yesterday. Of course you'll probably want to > retrieve the pages from a database table but I hope this helps. > The first step is to setup your DNS. The easiest way is to edit your > /etc/hosts file: > # add this entry > 127.0.0.1 localhost www.a.com www.b.com > # your mutisite.py, if you're on OS X or *nix you have to run it as root > because its a port below 1000 (sudo python multisite.py) > from flask import Flask, request > app = Flask(__name__) > @app.route('/') > def index(): > # Return different results depending on the host > url = split_url(request.url) > if "www.a.com" == url['domain']: > return "<h1>You are visiting www.a.com</h1><p>Here's your URL " + > request.url + "</p>" > else: > return "<h1>You are not visiting www.a.com</h1><p>Here's your URL " > + request.url + "</p>" > > def split_url(url): > "Returns the full URL in two parts, the domain, and the path" > url = url.split('/', 3) > return {'domain': url[2], 'path': url[3]} > # run webserver only if this script is not imported > if __name__ == '__main__': > app.debug = True > app.run(port=80, host="0.0.0.0") > I decided to do this as a werkzeug app after my testing. I can't remember > why though! > Chris > > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote: >> >> Hey all, >> >> >> >> Searched for a little while, but wasn’t really able to find an answer to >> this. Is there a way to use flask with multiple domains (not subdomains)? >> It would be nice to say have domain ‘siteone.com’ route to ‘/siteone’ and >> ‘sitetwo.com’ that routes to ‘/sitetwo’. >> >> >> >> Any help would be appreciated! >> >> >> >> Cheers, >> >> Cory >
I currently run uWSGI and Nginx for production but the previous code is for testing an idea with the minimum amount of effort. Thanks for the tips. The WSGI dispatcher is awesome. I don't have a use for it right now but I foresee it being useful in the future. Chris On Sat, Jun 11, 2011 at 12:53 PM, Ron DuPlain <ron.duplain@gmail.com> wrote: > If you want to run multiple applications in the same interpreter, take > a look at: > http://flask.pocoo.org/docs/patterns/appdispatch/ > > Note that the builtin web server on Flask [app.run(...)] is only > intended for development use. If for some reason you are running the > development server on a publicly accessible URL (e.g. temporary > review), then be sure app.debug == False. Otherwise, anyone who > triggers the debugger can run code on your server using the Werkzeug > debugger's (awesome for development) interactive features. > > -Ron > > > On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule <guitarift@gmail.com> > wrote: > > I was pondering the same thing myself. My idea was to serve multiple > > websites from one python interpreter to make better utilization of > CPU/RAM. > > I was just testing this out yesterday. Of course you'll probably want to > > retrieve the pages from a database table but I hope this helps. > > The first step is to setup your DNS. The easiest way is to edit your > > /etc/hosts file: > > # add this entry > > 127.0.0.1 localhost www.a.com www.b.com > > # your mutisite.py, if you're on OS X or *nix you have to run it as root > > because its a port below 1000 (sudo python multisite.py) > > from flask import Flask, request > > app = Flask(__name__) > > @app.route('/') > > def index(): > > # Return different results depending on the host > > url = split_url(request.url) > > if "www.a.com" == url['domain']: > > return "<h1>You are visiting www.a.com</h1><p>Here's your URL " > + > > request.url + "</p>" > > else: > > return "<h1>You are not visiting www.a.com</h1><p>Here's your > URL " > > + request.url + "</p>" > > > > def split_url(url): > > "Returns the full URL in two parts, the domain, and the path" > > url = url.split('/', 3) > > return {'domain': url[2], 'path': url[3]} > > # run webserver only if this script is not imported > > if __name__ == '__main__': > > app.debug = True > > app.run(port=80, host="0.0.0.0") > > I decided to do this as a werkzeug app after my testing. I can't remember > > why though! > > Chris > > > > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote: > >> > >> Hey all, > >> > >> > >> > >> Searched for a little while, but wasn’t really able to find an answer to > >> this. Is there a way to use flask with multiple domains (not > subdomains)? > >> It would be nice to say have domain ‘siteone.com’ route to ‘/siteone’ > and > >> ‘sitetwo.com’ that routes to ‘/sitetwo’. > >> > >> > >> > >> Any help would be appreciated! > >> > >> > >> > >> Cheers, > >> > >> Cory > > >
On Sat, Jun 11, 2011 at 7:20 PM, Chris Aliipule <guitarift@gmail.com> wrote: > I currently run uWSGI and Nginx for production but the previous code is for > testing an idea with the minimum amount of effort. Thanks for the tips. The > WSGI dispatcher is awesome. I don't have a use for it right now but I > foresee it being useful in the future. Sounds great! Have anything to add to this doc? https://raw.github.com/mitsuhiko/flask/master/docs/deploying/uwsgi.rst -Ron > Chris > > On Sat, Jun 11, 2011 at 12:53 PM, Ron DuPlain <ron.duplain@gmail.com> wrote: >> >> If you want to run multiple applications in the same interpreter, take >> a look at: >> http://flask.pocoo.org/docs/patterns/appdispatch/ >> >> Note that the builtin web server on Flask [app.run(...)] is only >> intended for development use. If for some reason you are running the >> development server on a publicly accessible URL (e.g. temporary >> review), then be sure app.debug == False. Otherwise, anyone who >> triggers the debugger can run code on your server using the Werkzeug >> debugger's (awesome for development) interactive features. >> >> -Ron >> >> >> On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule <guitarift@gmail.com> >> wrote: >> > I was pondering the same thing myself. My idea was to serve multiple >> > websites from one python interpreter to make better utilization of >> > CPU/RAM. >> > I was just testing this out yesterday. Of course you'll probably want to >> > retrieve the pages from a database table but I hope this helps. >> > The first step is to setup your DNS. The easiest way is to edit your >> > /etc/hosts file: >> > # add this entry >> > 127.0.0.1 localhost www.a.com www.b.com >> > # your mutisite.py, if you're on OS X or *nix you have to run it as root >> > because its a port below 1000 (sudo python multisite.py) >> > from flask import Flask, request >> > app = Flask(__name__) >> > @app.route('/') >> > def index(): >> > # Return different results depending on the host >> > url = split_url(request.url) >> > if "www.a.com" == url['domain']: >> > return "<h1>You are visiting www.a.com</h1><p>Here's your URL " >> > + >> > request.url + "</p>" >> > else: >> > return "<h1>You are not visiting www.a.com</h1><p>Here's your >> > URL " >> > + request.url + "</p>" >> > >> > def split_url(url): >> > "Returns the full URL in two parts, the domain, and the path" >> > url = url.split('/', 3) >> > return {'domain': url[2], 'path': url[3]} >> > # run webserver only if this script is not imported >> > if __name__ == '__main__': >> > app.debug = True >> > app.run(port=80, host="0.0.0.0") >> > I decided to do this as a werkzeug app after my testing. I can't >> > remember >> > why though! >> > Chris >> > >> > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote: >> >> >> >> Hey all, >> >> >> >> >> >> >> >> Searched for a little while, but wasn’t really able to find an answer >> >> to >> >> this. Is there a way to use flask with multiple domains (not >> >> subdomains)? >> >> It would be nice to say have domain ‘siteone.com’ route to ‘/siteone’ >> >> and >> >> ‘sitetwo.com’ that routes to ‘/sitetwo’. >> >> >> >> >> >> >> >> Any help would be appreciated! >> >> >> >> >> >> >> >> Cheers, >> >> >> >> Cory >> > > >
Sorry Cory this is off topic. I haven't deployed a Flask app yet because I'm new to Flask. I use uWSGI a little differently in production. In Ubuntu I have Upstart managing my uWSGI process and prefer to run it on a port instead of a UNIX socket: # /etc/init/uwsgi-a.com description "uWSGI - www.a.com" start on runlevel [2345] stop on runlevel [!2345] respawn env PROJECT=/var/www/a.com env SOCKET=127.0.0.1:5000 env BINPATH=/usr/bin/uwsgi exec $BINPATH -s $SOCKET -w run-wsgi --pythonpath $PROJECT # /var/www/a.com/run-wsgi.py - This is for running a Django project, a Flask app would be different import os import django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' application = django.core.handlers.wsgi.WSGIHandler() I find Upstart a little tricky but I'd rather not install another process manager, Chris On Sat, Jun 11, 2011 at 1:45 PM, Ron DuPlain <ron.duplain@gmail.com> wrote: > On Sat, Jun 11, 2011 at 7:20 PM, Chris Aliipule <guitarift@gmail.com> > wrote: > > I currently run uWSGI and Nginx for production but the previous code is > for > > testing an idea with the minimum amount of effort. Thanks for the tips. > The > > WSGI dispatcher is awesome. I don't have a use for it right now but I > > foresee it being useful in the future. > > Sounds great! Have anything to add to this doc? > https://raw.github.com/mitsuhiko/flask/master/docs/deploying/uwsgi.rst > > -Ron > > > > Chris > > > > On Sat, Jun 11, 2011 at 12:53 PM, Ron DuPlain <ron.duplain@gmail.com> > wrote: > >> > >> If you want to run multiple applications in the same interpreter, take > >> a look at: > >> http://flask.pocoo.org/docs/patterns/appdispatch/ > >> > >> Note that the builtin web server on Flask [app.run(...)] is only > >> intended for development use. If for some reason you are running the > >> development server on a publicly accessible URL (e.g. temporary > >> review), then be sure app.debug == False. Otherwise, anyone who > >> triggers the debugger can run code on your server using the Werkzeug > >> debugger's (awesome for development) interactive features. > >> > >> -Ron > >> > >> > >> On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule <guitarift@gmail.com> > >> wrote: > >> > I was pondering the same thing myself. My idea was to serve multiple > >> > websites from one python interpreter to make better utilization of > >> > CPU/RAM. > >> > I was just testing this out yesterday. Of course you'll probably want > to > >> > retrieve the pages from a database table but I hope this helps. > >> > The first step is to setup your DNS. The easiest way is to edit your > >> > /etc/hosts file: > >> > # add this entry > >> > 127.0.0.1 localhost www.a.com www.b.com > >> > # your mutisite.py, if you're on OS X or *nix you have to run it as > root > >> > because its a port below 1000 (sudo python multisite.py) > >> > from flask import Flask, request > >> > app = Flask(__name__) > >> > @app.route('/') > >> > def index(): > >> > # Return different results depending on the host > >> > url = split_url(request.url) > >> > if "www.a.com" == url['domain']: > >> > return "<h1>You are visiting www.a.com</h1><p>Here's your URL > " > >> > + > >> > request.url + "</p>" > >> > else: > >> > return "<h1>You are not visiting www.a.com</h1><p>Here's your > >> > URL " > >> > + request.url + "</p>" > >> > > >> > def split_url(url): > >> > "Returns the full URL in two parts, the domain, and the path" > >> > url = url.split('/', 3) > >> > return {'domain': url[2], 'path': url[3]} > >> > # run webserver only if this script is not imported > >> > if __name__ == '__main__': > >> > app.debug = True > >> > app.run(port=80, host="0.0.0.0") > >> > I decided to do this as a werkzeug app after my testing. I can't > >> > remember > >> > why though! > >> > Chris > >> > > >> > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote: > >> >> > >> >> Hey all, > >> >> > >> >> > >> >> > >> >> Searched for a little while, but wasn’t really able to find an answer > >> >> to > >> >> this. Is there a way to use flask with multiple domains (not > >> >> subdomains)? > >> >> It would be nice to say have domain ‘siteone.com’ route to > ‘/siteone’ > >> >> and > >> >> ‘sitetwo.com’ that routes to ‘/sitetwo’. > >> >> > >> >> > >> >> > >> >> Any help would be appreciated! > >> >> > >> >> > >> >> > >> >> Cheers, > >> >> > >> >> Cory > >> > > > > > >
I use this little extension to load the right bit of metadata for each site
from my config file:
from flask import _request_ctx_stack
import re
class MetaInfo(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
def before_request(self):
ctx = _request_ctx_stack.top
sites = self.app.config['META'].keys()
for site in sites:
if site in ctx.request.host:
self.app.meta = self.app.config['META'][site]
break
def init_app(self, app):
self.app = app
self.app.before_request(self.before_request)
and then in the config file you can store site relevant infor:
META = {
'localhost': { # dict of development stuff
...
},
'example1.com' { # dict of example1 stuff
...
},
'example2.com' { # dict of example2 stuff
...
},
'example3.com' { # dict of example3 stuff
...
},
}
On Sun, Jun 12, 2011 at 2:18 AM, Chris Aliipule <guitarift@gmail.com> wrote:
> Sorry Cory this is off topic.
>
> I haven't deployed a Flask app yet because I'm new to Flask. I use uWSGI a
> little differently in production.
>
> In Ubuntu I have Upstart managing my uWSGI process and prefer to run it on
> a port instead of a UNIX socket:
>
> # /etc/init/uwsgi-a.com
>
> description "uWSGI - www.a.com"
>
> start on runlevel [2345]
> stop on runlevel [!2345]
>
> respawn
>
> env PROJECT=/var/www/a.com
> env SOCKET=127.0.0.1:5000
> env BINPATH=/usr/bin/uwsgi
>
> exec $BINPATH -s $SOCKET -w run-wsgi --pythonpath $PROJECT
>
>
> # /var/www/a.com/run-wsgi.py - This is for running a Django project, a
> Flask app would be different
> import os
> import django.core.handlers.wsgi
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
> application = django.core.handlers.wsgi.WSGIHandler()
>
>
> I find Upstart a little tricky but I'd rather not install another process
> manager,
> Chris
>
> On Sat, Jun 11, 2011 at 1:45 PM, Ron DuPlain <ron.duplain@gmail.com>wrote:
>
>> On Sat, Jun 11, 2011 at 7:20 PM, Chris Aliipule <guitarift@gmail.com>
>> wrote:
>> > I currently run uWSGI and Nginx for production but the previous code is
>> for
>> > testing an idea with the minimum amount of effort. Thanks for the tips.
>> The
>> > WSGI dispatcher is awesome. I don't have a use for it right now but I
>> > foresee it being useful in the future.
>>
>> Sounds great! Have anything to add to this doc?
>> https://raw.github.com/mitsuhiko/flask/master/docs/deploying/uwsgi.rst
>>
>> -Ron
>>
>>
>> > Chris
>> >
>> > On Sat, Jun 11, 2011 at 12:53 PM, Ron DuPlain <ron.duplain@gmail.com>
>> wrote:
>> >>
>> >> If you want to run multiple applications in the same interpreter, take
>> >> a look at:
>> >> http://flask.pocoo.org/docs/patterns/appdispatch/
>> >>
>> >> Note that the builtin web server on Flask [app.run(...)] is only
>> >> intended for development use. If for some reason you are running the
>> >> development server on a publicly accessible URL (e.g. temporary
>> >> review), then be sure app.debug == False. Otherwise, anyone who
>> >> triggers the debugger can run code on your server using the Werkzeug
>> >> debugger's (awesome for development) interactive features.
>> >>
>> >> -Ron
>> >>
>> >>
>> >> On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule <guitarift@gmail.com>
>> >> wrote:
>> >> > I was pondering the same thing myself. My idea was to serve multiple
>> >> > websites from one python interpreter to make better utilization of
>> >> > CPU/RAM.
>> >> > I was just testing this out yesterday. Of course you'll probably want
>> to
>> >> > retrieve the pages from a database table but I hope this helps.
>> >> > The first step is to setup your DNS. The easiest way is to edit your
>> >> > /etc/hosts file:
>> >> > # add this entry
>> >> > 127.0.0.1 localhost www.a.com www.b.com
>> >> > # your mutisite.py, if you're on OS X or *nix you have to run it as
>> root
>> >> > because its a port below 1000 (sudo python multisite.py)
>> >> > from flask import Flask, request
>> >> > app = Flask(__name__)
>> >> > @app.route('/')
>> >> > def index():
>> >> > # Return different results depending on the host
>> >> > url = split_url(request.url)
>> >> > if "www.a.com" == url['domain']:
>> >> > return "<h1>You are visiting www.a.com</h1><p>Here's your
>> URL "
>> >> > +
>> >> > request.url + "</p>"
>> >> > else:
>> >> > return "<h1>You are not visiting www.a.com</h1><p>Here's
>> your
>> >> > URL "
>> >> > + request.url + "</p>"
>> >> >
>> >> > def split_url(url):
>> >> > "Returns the full URL in two parts, the domain, and the path"
>> >> > url = url.split('/', 3)
>> >> > return {'domain': url[2], 'path': url[3]}
>> >> > # run webserver only if this script is not imported
>> >> > if __name__ == '__main__':
>> >> > app.debug = True
>> >> > app.run(port=80, host="0.0.0.0")
>> >> > I decided to do this as a werkzeug app after my testing. I can't
>> >> > remember
>> >> > why though!
>> >> > Chris
>> >> >
>> >> > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li <coryli@mit.edu> wrote:
>> >> >>
>> >> >> Hey all,
>> >> >>
>> >> >>
>> >> >>
>> >> >> Searched for a little while, but wasn’t really able to find an
>> answer
>> >> >> to
>> >> >> this. Is there a way to use flask with multiple domains (not
>> >> >> subdomains)?
>> >> >> It would be nice to say have domain ‘siteone.com’ route to
>> ‘/siteone’
>> >> >> and
>> >> >> ‘sitetwo.com’ that routes to ‘/sitetwo’.
>> >> >>
>> >> >>
>> >> >>
>> >> >> Any help would be appreciated!
>> >> >>
>> >> >>
>> >> >>
>> >> >> Cheers,
>> >> >>
>> >> >> Cory
>> >> >
>> >
>> >
>>
>
>
Thanks for notes everyone. :)
As a side question, would something like multi-domain routing be easily
doable with the upcoming blueprints system?
~Cory
From: flask@librelist.com [mailto:flask@librelist.com] On Behalf Of Col Wilson
Sent: Saturday, June 11, 2011 11:58 PM
To: flask@librelist.com
Subject: Re: [flask] Using Flask with Multiple Domains
I use this little extension to load the right bit of metadata for each
site from my config file:
from flask import _request_ctx_stack
import re
class MetaInfo(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
def before_request(self):
ctx = _request_ctx_stack.top
sites = self.app.config['META'].keys()
for site in sites:
if site in ctx.request.host:
self.app.meta = self.app.config['META'][site]
break
def init_app(self, app):
self.app = app
self.app.before_request(self.before_request)
and then in the config file you can store site relevant infor:
META = {
'localhost': { # dict of development stuff
...
},
'example1.com<http://example1.com>' { # dict of example1 stuff
...
},
'example2.com<http://example2.com>' { # dict of example2 stuff
...
},
'example3.com<http://example3.com>' { # dict of example3 stuff
...
},
}
On Sun, Jun 12, 2011 at 2:18 AM, Chris Aliipule
<guitarift@gmail.com<mailto:guitarift@gmail.com>> wrote:
Sorry Cory this is off topic.
I haven't deployed a Flask app yet because I'm new to Flask. I use uWSGI a
little differently in production.
In Ubuntu I have Upstart managing my uWSGI process and prefer to run it on
a port instead of a UNIX socket:
# /etc/init/uwsgi-a.com<http://uwsgi-a.com>
description "uWSGI - www.a.com<http://www.a.com>"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
env PROJECT=/var/www/a.com<http://a.com>
env SOCKET=127.0.0.1:5000<http://127.0.0.1:5000>
env BINPATH=/usr/bin/uwsgi
exec $BINPATH -s $SOCKET -w run-wsgi --pythonpath $PROJECT
# /var/www/a.com/run-wsgi.py<http://a.com/run-wsgi.py> - This is for
running a Django project, a Flask app would be different
import os
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
I find Upstart a little tricky but I'd rather not install another process manager,
Chris
On Sat, Jun 11, 2011 at 1:45 PM, Ron DuPlain
<ron.duplain@gmail.com<mailto:ron.duplain@gmail.com>> wrote:
On Sat, Jun 11, 2011 at 7:20 PM, Chris Aliipule
<guitarift@gmail.com<mailto:guitarift@gmail.com>> wrote:
> I currently run uWSGI and Nginx for production but the previous code is for
> testing an idea with the minimum amount of effort. Thanks for the tips. The
> WSGI dispatcher is awesome. I don't have a use for it right now but I
> foresee it being useful in the future.
Sounds great! Have anything to add to this doc?
https://raw.github.com/mitsuhiko/flask/master/docs/deploying/uwsgi.rst
-Ron
> Chris
>
> On Sat, Jun 11, 2011 at 12:53 PM, Ron DuPlain
<ron.duplain@gmail.com<mailto:ron.duplain@gmail.com>> wrote:
>>
>> If you want to run multiple applications in the same interpreter, take
>> a look at:
>> http://flask.pocoo.org/docs/patterns/appdispatch/
>>
>> Note that the builtin web server on Flask [app.run(...)] is only
>> intended for development use. If for some reason you are running the
>> development server on a publicly accessible URL (e.g. temporary
>> review), then be sure app.debug == False. Otherwise, anyone who
>> triggers the debugger can run code on your server using the Werkzeug
>> debugger's (awesome for development) interactive features.
>>
>> -Ron
>>
>>
>> On Sat, Jun 11, 2011 at 6:47 PM, Chris Aliipule
<guitarift@gmail.com<mailto:guitarift@gmail.com>>
>> wrote:
>> > I was pondering the same thing myself. My idea was to serve multiple
>> > websites from one python interpreter to make better utilization of
>> > CPU/RAM.
>> > I was just testing this out yesterday. Of course you'll probably want to
>> > retrieve the pages from a database table but I hope this helps.
>> > The first step is to setup your DNS. The easiest way is to edit your
>> > /etc/hosts file:
>> > # add this entry
>> > 127.0.0.1 localhost www.a.com<http://www.a.com> www.b.com<http://www.b.com>
>> > # your mutisite.py, if you're on OS X or *nix you have to run it as root
>> > because its a port below 1000 (sudo python multisite.py)
>> > from flask import Flask, request
>> > app = Flask(__name__)
>> > @app.route('/')
>> > def index():
>> > # Return different results depending on the host
>> > url = split_url(request.url)
>> > if "www.a.com<http://www.a.com>" == url['domain']:
>> > return "<h1>You are visiting
www.a.com<http://www.a.com></h1><p>Here's your URL "
>> > +
>> > request.url + "</p>"
>> > else:
>> > return "<h1>You are not visiting
www.a.com<http://www.a.com></h1><p>Here's your
>> > URL "
>> > + request.url + "</p>"
>> >
>> > def split_url(url):
>> > "Returns the full URL in two parts, the domain, and the path"
>> > url = url.split('/', 3)
>> > return {'domain': url[2], 'path': url[3]}
>> > # run webserver only if this script is not imported
>> > if __name__ == '__main__':
>> > app.debug = True
>> > app.run(port=80, host="0.0.0.0")
>> > I decided to do this as a werkzeug app after my testing. I can't
>> > remember
>> > why though!
>> > Chris
>> >
>> > On Sat, Jun 11, 2011 at 9:06 AM, Cory Li
<coryli@mit.edu<mailto:coryli@mit.edu>> wrote:
>> >>
>> >> Hey all,
>> >>
>> >>
>> >>
>> >> Searched for a little while, but wasn’t really able to find an answer
>> >> to
>> >> this. Is there a way to use flask with multiple domains (not
>> >> subdomains)?
>> >> It would be nice to say have domain
‘siteone.com<http://siteone.com>’ route to ‘/siteone’
>> >> and
>> >> ‘sitetwo.com<http://sitetwo.com>’ that routes to ‘/sitetwo’.
>> >>
>> >>
>> >>
>> >> Any help would be appreciated!
>> >>
>> >>
>> >>
>> >> Cheers,
>> >>
>> >> Cory
>> >
>
>
Hi, On 2011-06-12 12:36 PM, Cory Li wrote: > As a side question, would something like multi-domain routing be easily > doable with the upcoming blueprints system? Not initially, but we have plans to make the subdomain based routing a special case of domain based routing which at one point should be in Werkzeug. When that happens it will be available for Flask users through blueprints. Regards, Armin
Hi Cory, On Sat, Jun 11, 2011 at 3:06 PM, Cory Li <coryli@mit.edu> wrote: > Searched for a little while, but wasn’t really able to find an answer to > this. Is there a way to use flask with multiple domains (not subdomains)? > It would be nice to say have domain ‘siteone.com’ route to ‘/siteone’ and > ‘sitetwo.com’ that routes to ‘/sitetwo’. You'd set this up via the web server in which you deploy your flask applications. See http://flask.pocoo.org/docs/deploying/ and look for virtual host configuration options with your httpd. -Ron