Hi ! Suppose there is a web app name thesite.com. I need to give every user a url of his own. For eg- if alice signs up, she gets a space of her own at the url "alice.thesite.com".. How do I achieve this. Thanks Alice
Le 01/05/2011 14:39, alice ni a écrit : > Hi ! > Suppose there is a web app name thesite.com. I need to give every user > a url of his own. For eg- if alice signs up, she gets a space of her > own at the url "alice.thesite.com".. How do I achieve this. > > Thanks > Alice Hi, The online documentation seems to be down right now, but the @app.route() decorator passes any extra option to the underlying Rule object[1]. This includes `subdomain`[2] which can itself contain <variables>. [1] https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L646 [2] https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/routing.py#L416 Try something like this: @app.route('/object<int:id>', subdomain='<username>') def foo(username, id): return 'User %s got object %i.' % (username.title(), id) http://alice.example.net/object42 should give "User Alice got object 42." Repeating subdomain='<username>' on every view can be cumbersome. Instead try looking at request.path in a @app.before_request function and putting the result in g.username, or maybe a WSGI middleware, ... Of course, in any cases, you need to configure your server to send all relevant requests to Flask. Regards, -- Simon Sapin http://exyr.org/
Ah, that is a nice solution. Didn't know about this. Thanks for this Simon. On 1 May 2011 18:41, Simon Sapin <simon.sapin@exyr.org> wrote: > Le 01/05/2011 14:39, alice ni a écrit : > > Hi ! > > Suppose there is a web app name thesite.com. I need to give every user > > a url of his own. For eg- if alice signs up, she gets a space of her > > own at the url "alice.thesite.com".. How do I achieve this. > > > > Thanks > > Alice > > Hi, > > The online documentation seems to be down right now, but the > @app.route() decorator passes any extra option to the underlying Rule > object[1]. This includes `subdomain`[2] which can itself contain > <variables>. > > [1] https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L646 > [2] > https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/routing.py#L416 > > Try something like this: > > @app.route('/object<int:id>', subdomain='<username>') > def foo(username, id): > return 'User %s got object %i.' % (username.title(), id) > > http://alice.example.net/object42 should give "User Alice got object 42." > > Repeating subdomain='<username>' on every view can be cumbersome. > Instead try looking at request.path in a @app.before_request function > and putting the result in g.username, or maybe a WSGI middleware, ... > > Of course, in any cases, you need to configure your server to send all > relevant requests to Flask. > > Regards, > -- > Simon Sapin > http://exyr.org/ > -- Regards, Ishbir Singh
You'll have to do this with the help of your webserver. Tell it to forward all URLs of the format *.thesite.com to thesite.com/user/* or something like this. Lookup the documentation of your web server. On 1 May 2011 18:09, alice ni <alice.ni19@gmail.com> wrote: > Hi ! > Suppose there is a web app name thesite.com. I need to give every user > a url of his own. For eg- if alice signs up, she gets a space of her > own at the url "alice.thesite.com".. How do I achieve this. > > Thanks > Alice > -- Regards, Ishbir Singh