librelist archives

« back to archive

Regular expressions in flask urls

Regular expressions in flask urls

From:
Gamesbrainiac
Date:
2013-07-13 @ 10:22
Hi!

I want to use regular expressions in flask URLS.

For example:

@app.route(r'/')
@app.route(r'/index/?')
def index():...

I want it so that, it does not matter if you have localhost:8080/index or
localhost:8080/index/. How do I do this?

-- 
Kind Regards,

Quazi Nafiul Islam

Re: [flask] Regular expressions in flask urls

From:
Stefane Fermigier
Date:
2013-07-13 @ 10:32
https://www.google.com/search?q=regular+expressions+in+flask+URLS

Also, for your use case, it's not a good idea. It's better to have just 
one URL for a given page, with a redirect from possible variants. And 
that's what Flask does by default.

  S.

On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:

> Hi!
> 
> I want to use regular expressions in flask URLS.
> 
> For example:
> 
> @app.route(r'/')
> @app.route(r'/index/?')
> def index():...
> 
> I want it so that, it does not matter if you have localhost:8080/index 
or localhost:8080/index/. How do I do this?
> 
> -- 
> Kind Regards,
> 
> Quazi Nafiul Islam

-- 
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier 
- http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
Co-Founder and Chairman, Free&OSS Cluster - http://www.gt-logiciel-libre.org/
Co-Founder & Vice-President, National Council for Free&OSS - http://cnll.fr/
Vice President, Open World Forum 2013 - http://openworldforum.org/
"Well done is better than well said." - Benjamin Franklin
"There's no such thing as can't. You always have a choice." - Ken Gor

Re: [flask] Regular expressions in flask urls

From:
Gamesbrainiac
Date:
2013-07-13 @ 10:37
Yes, I've just seen that, but it does not compile the regular expressions,
meaning that would be slow would it not?


On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:

> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>
> Also, for your use case, it's not a good idea. It's better to have just
> one URL for a given page, with a redirect from possible variants. And
> that's what Flask does by default.
>
>   S.
>
> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>
> Hi!
>
> I want to use regular expressions in flask URLS.
>
> For example:
>
> @app.route(r'/')
> @app.route(r'/index/?')
> def index():...
>
> I want it so that, it does not matter if you have localhost:8080/index or
> localhost:8080/index/. How do I do this?
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>
>
> --
> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
> http://linkedin.com/in/sfermigier
> Founder & CEO, Abilian - Enterprise Social Software -
> http://www.abilian.com/
> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
> Co-Founder and Chairman, Free&OSS Cluster -
> http://www.gt-logiciel-libre.org/
> Co-Founder & Vice-President, National Council for Free&OSS -
> http://cnll.fr/
> Vice President, Open World Forum 2013 - http://openworldforum.org/
> "Well done is better than well said." - Benjamin Franklin
> "There's no such thing as can't. You always have a choice." - Ken Gor
>
>


-- 
Kind Regards,

Quazi Nafiul Islam

Re: [flask] Regular expressions in flask urls

From:
Stefane Fermigier
Date:
2013-07-13 @ 12:03
Hi,

Flask (actually, Werzkzeug) already uses regexes internally for its 
routing machinery (cf. the werzeug.routing module), and of course those 
regexes are already compiled so there is no performance penalty at all.

  S.

On Jul 13, 2013, at 12:37 PM, Gamesbrainiac wrote:

> Yes, I've just seen that, but it does not compile the regular 
expressions, meaning that would be slow would it not?
> 
> 
> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
> https://www.google.com/search?q=regular+expressions+in+flask+URLS
> 
> Also, for your use case, it's not a good idea. It's better to have just 
one URL for a given page, with a redirect from possible variants. And 
that's what Flask does by default.
> 
>   S.
> 
> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
> 
>> Hi!
>> 
>> I want to use regular expressions in flask URLS.
>> 
>> For example:
>> 
>> @app.route(r'/')
>> @app.route(r'/index/?')
>> def index():...
>> 
>> I want it so that, it does not matter if you have localhost:8080/index 
or localhost:8080/index/. How do I do this?
>> 
>> -- 
>> Kind Regards,
>> 
>> Quazi Nafiul Islam
> 
> -- 
> Stefane Fermigier - http://fermigier.com/ - 
http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
> Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
> Co-Founder and Chairman, Free&OSS Cluster - http://www.gt-logiciel-libre.org/
> Co-Founder & Vice-President, National Council for Free&OSS - http://cnll.fr/
> Vice President, Open World Forum 2013 - http://openworldforum.org/
> "Well done is better than well said." - Benjamin Franklin
> "There's no such thing as can't. You always have a choice." - Ken Gor
> 
> 
> 
> 
> -- 
> Kind Regards,
> 
> Quazi Nafiul Islam

-- 
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier 
- http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
Co-Founder and Chairman, Free&OSS Cluster - http://www.gt-logiciel-libre.org/
Co-Founder & Vice-President, National Council for Free&OSS - http://cnll.fr/
Vice President, Open World Forum 2013 - http://openworldforum.org/
"Well done is better than well said." - Benjamin Franklin
"There's no such thing as can't. You always have a choice." - Ken Gor

Re: [flask] Regular expressions in flask urls

From:
Gamesbrainiac
Date:
2013-07-13 @ 12:26
Thanks for the clarification.
On Jul 13, 2013 6:06 PM, "Stefane Fermigier" <sfermigier@abilian.com> wrote:

> Hi,
>
> Flask (actually, Werzkzeug) already uses regexes internally for its
> routing machinery (cf. the werzeug.routing module), and of course those
> regexes are already compiled so there is no performance penalty at all.
>
>   S.
>
> On Jul 13, 2013, at 12:37 PM, Gamesbrainiac wrote:
>
> Yes, I've just seen that, but it does not compile the regular expressions,
> meaning that would be slow would it not?
>
>
> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>
>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>
>> Also, for your use case, it's not a good idea. It's better to have just
>> one URL for a given page, with a redirect from possible variants. And
>> that's what Flask does by default.
>>
>>   S.
>>
>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>
>> Hi!
>>
>> I want to use regular expressions in flask URLS.
>>
>> For example:
>>
>> @app.route(r'/')
>> @app.route(r'/index/?')
>> def index():...
>>
>> I want it so that, it does not matter if you have localhost:8080/index
>> or localhost:8080/index/. How do I do this?
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>>
>> --
>> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
>> http://linkedin.com/in/sfermigier
>> Founder & CEO, Abilian - Enterprise Social Software -
>> http://www.abilian.com/
>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>> Co-Founder and Chairman, Free&OSS Cluster -
>> http://www.gt-logiciel-libre.org/
>> Co-Founder & Vice-President, National Council for Free&OSS -
>> http://cnll.fr/
>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>> "Well done is better than well said." - Benjamin Franklin
>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>
>>
>
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>
>
> --
> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
> http://linkedin.com/in/sfermigier
> Founder & CEO, Abilian - Enterprise Social Software -
> http://www.abilian.com/
> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
> Co-Founder and Chairman, Free&OSS Cluster -
> http://www.gt-logiciel-libre.org/
> Co-Founder & Vice-President, National Council for Free&OSS -
> http://cnll.fr/
> Vice President, Open World Forum 2013 - http://openworldforum.org/
> "Well done is better than well said." - Benjamin Franklin
> "There's no such thing as can't. You always have a choice." - Ken Gor
>
>

Re: [flask] Regular expressions in flask urls

From:
Philippe Ndiaye
Date:
2013-07-13 @ 13:03
Thanks :)


On Sat, Jul 13, 2013 at 2:03 PM, Stefane Fermigier
<sfermigier@abilian.com>wrote:

> Hi,
>
> Flask (actually, Werzkzeug) already uses regexes internally for its
> routing machinery (cf. the werzeug.routing module), and of course those
> regexes are already compiled so there is no performance penalty at all.
>
>   S.
>
> On Jul 13, 2013, at 12:37 PM, Gamesbrainiac wrote:
>
> Yes, I've just seen that, but it does not compile the regular expressions,
> meaning that would be slow would it not?
>
>
> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>
>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>
>> Also, for your use case, it's not a good idea. It's better to have just
>> one URL for a given page, with a redirect from possible variants. And
>> that's what Flask does by default.
>>
>>   S.
>>
>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>
>> Hi!
>>
>> I want to use regular expressions in flask URLS.
>>
>> For example:
>>
>> @app.route(r'/')
>> @app.route(r'/index/?')
>> def index():...
>>
>> I want it so that, it does not matter if you have localhost:8080/index
>> or localhost:8080/index/. How do I do this?
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>>
>> --
>> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
>> http://linkedin.com/in/sfermigier
>> Founder & CEO, Abilian - Enterprise Social Software -
>> http://www.abilian.com/
>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>> Co-Founder and Chairman, Free&OSS Cluster -
>> http://www.gt-logiciel-libre.org/
>> Co-Founder & Vice-President, National Council for Free&OSS -
>> http://cnll.fr/
>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>> "Well done is better than well said." - Benjamin Franklin
>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>
>>
>
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>
>
> --
> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
> http://linkedin.com/in/sfermigier
> Founder & CEO, Abilian - Enterprise Social Software -
> http://www.abilian.com/
> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
> Co-Founder and Chairman, Free&OSS Cluster -
> http://www.gt-logiciel-libre.org/
> Co-Founder & Vice-President, National Council for Free&OSS -
> http://cnll.fr/
> Vice President, Open World Forum 2013 - http://openworldforum.org/
> "Well done is better than well said." - Benjamin Franklin
> "There's no such thing as can't. You always have a choice." - Ken Gor
>
>


-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Regular expressions in flask urls

From:
Mauricio de Abreu Antunes
Date:
2013-07-13 @ 13:09
Well, you can just use the defaults (string, int, float and path) to mount
your route.
Inside your function you can use a support function to analyze if your URL
parameters were satisfied.
Does the above solution help you?


2013/7/13 Philippe NDIAYE <phndiaye@gmail.com>

> Thanks :)
>
>
> On Sat, Jul 13, 2013 at 2:03 PM, Stefane Fermigier <sfermigier@abilian.com
> > wrote:
>
>> Hi,
>>
>> Flask (actually, Werzkzeug) already uses regexes internally for its
>> routing machinery (cf. the werzeug.routing module), and of course those
>> regexes are already compiled so there is no performance penalty at all.
>>
>>   S.
>>
>> On Jul 13, 2013, at 12:37 PM, Gamesbrainiac wrote:
>>
>> Yes, I've just seen that, but it does not compile the regular
>> expressions, meaning that would be slow would it not?
>>
>>
>> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>>
>>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>>
>>> Also, for your use case, it's not a good idea. It's better to have just
>>> one URL for a given page, with a redirect from possible variants. And
>>> that's what Flask does by default.
>>>
>>>   S.
>>>
>>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>>
>>> Hi!
>>>
>>> I want to use regular expressions in flask URLS.
>>>
>>> For example:
>>>
>>> @app.route(r'/')
>>> @app.route(r'/index/?')
>>> def index():...
>>>
>>> I want it so that, it does not matter if you have localhost:8080/index
>>> or localhost:8080/index/. How do I do this?
>>>
>>> --
>>> Kind Regards,
>>>
>>> Quazi Nafiul Islam
>>>
>>>
>>> --
>>> Stefane Fermigier - http://fermigier.com/ -
>>> http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
>>> Founder & CEO, Abilian - Enterprise Social Software -
>>> http://www.abilian.com/
>>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>>> Co-Founder and Chairman, Free&OSS Cluster -
>>> http://www.gt-logiciel-libre.org/
>>> Co-Founder & Vice-President, National Council for Free&OSS -
>>> http://cnll.fr/
>>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>>> "Well done is better than well said." - Benjamin Franklin
>>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>>
>>>
>>
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>>
>>  --
>> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
>> http://linkedin.com/in/sfermigier
>> Founder & CEO, Abilian - Enterprise Social Software -
>> http://www.abilian.com/
>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>> Co-Founder and Chairman, Free&OSS Cluster -
>> http://www.gt-logiciel-libre.org/
>> Co-Founder & Vice-President, National Council for Free&OSS -
>> http://cnll.fr/
>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>> "Well done is better than well said." - Benjamin Franklin
>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>
>>
>
>
> --
> Regards,
> *
> *
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux Sysadmin  & Python programmer
>



-- 
*Mauricio de Abreu Antunes*
Mobile: (51)930-74-525
Skype: mauricio.abreua

Re: [flask] Regular expressions in flask urls

From:
Adam Patterson
Date:
2013-07-15 @ 18:34
For future reference, I use a regex url like so

# helpers.py
from werkzeug.routing import BaseConverter

class RegexConverter(BaseConverter):

    Rule('/<regex("about|help|contact"):page_name>/')

    """
    def __init__(self, url_map, *regex):
        super(RegexConverter, self).__init__(url_map)
        self.regex = regex[0]

# init.py
from .helpers import RegexConverter
app.url_map.converters['regex'] = RegexConverter





On Sat, Jul 13, 2013 at 6:09 AM, Mauricio de Abreu Antunes <
mauricio.abreua@gmail.com> wrote:

> Well, you can just use the defaults (string, int, float and path) to mount
> your route.
> Inside your function you can use a support function to analyze if your URL
> parameters were satisfied.
> Does the above solution help you?
>
>
> 2013/7/13 Philippe NDIAYE <phndiaye@gmail.com>
>
>> Thanks :)
>>
>>
>> On Sat, Jul 13, 2013 at 2:03 PM, Stefane Fermigier <
>> sfermigier@abilian.com> wrote:
>>
>>> Hi,
>>>
>>> Flask (actually, Werzkzeug) already uses regexes internally for its
>>> routing machinery (cf. the werzeug.routing module), and of course those
>>> regexes are already compiled so there is no performance penalty at all.
>>>
>>>   S.
>>>
>>> On Jul 13, 2013, at 12:37 PM, Gamesbrainiac wrote:
>>>
>>> Yes, I've just seen that, but it does not compile the regular
>>> expressions, meaning that would be slow would it not?
>>>
>>>
>>> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>>>
>>>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>>>
>>>> Also, for your use case, it's not a good idea. It's better to have just
>>>> one URL for a given page, with a redirect from possible variants. And
>>>> that's what Flask does by default.
>>>>
>>>>   S.
>>>>
>>>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>>>
>>>> Hi!
>>>>
>>>> I want to use regular expressions in flask URLS.
>>>>
>>>> For example:
>>>>
>>>> @app.route(r'/')
>>>> @app.route(r'/index/?')
>>>> def index():...
>>>>
>>>> I want it so that, it does not matter if you have localhost:8080/index
>>>> or localhost:8080/index/. How do I do this?
>>>>
>>>> --
>>>> Kind Regards,
>>>>
>>>> Quazi Nafiul Islam
>>>>
>>>>
>>>> --
>>>> Stefane Fermigier - http://fermigier.com/ -
>>>> http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
>>>> Founder & CEO, Abilian - Enterprise Social Software -
>>>> http://www.abilian.com/
>>>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>>>> Co-Founder and Chairman, Free&OSS Cluster -
>>>> http://www.gt-logiciel-libre.org/
>>>> Co-Founder & Vice-President, National Council for Free&OSS -
>>>> http://cnll.fr/
>>>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>>>> "Well done is better than well said." - Benjamin Franklin
>>>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>>>
>>>>
>>>
>>>
>>> --
>>> Kind Regards,
>>>
>>> Quazi Nafiul Islam
>>>
>>>
>>>  --
>>> Stefane Fermigier - http://fermigier.com/ -
>>> http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
>>> Founder & CEO, Abilian - Enterprise Social Software -
>>> http://www.abilian.com/
>>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>>> Co-Founder and Chairman, Free&OSS Cluster -
>>> http://www.gt-logiciel-libre.org/
>>> Co-Founder & Vice-President, National Council for Free&OSS -
>>> http://cnll.fr/
>>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>>> "Well done is better than well said." - Benjamin Franklin
>>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>>
>>>
>>
>>
>> --
>> Regards,
>> *
>> *
>> *Philippe Thécou NDIAYE*
>> IT Student @ SUPINFO Lyon
>> Linux Sysadmin  & Python programmer
>>
>
>
>
> --
> *Mauricio de Abreu Antunes*
> Mobile: (51)930-74-525
> Skype: mauricio.abreua
>

Re: [flask] Regular expressions in flask urls

From:
Philippe Ndiaye
Date:
2013-07-13 @ 10:47
In terms of speed, i really can't answer. But if i understand what you want
to do, i know Flask can do it all for you with variables rules.
For example, assuming you want to get the settings page of user, your url
can't be constant because you have many users.
So, with Flask you can do it like that:

  @app.route('/<username>/settings')
    def show_user_settings(username):
    # What you wan't to do on this page.

See the Variable Rules part of the quickstart for more informations:
http://flask.pocoo.org/docs/quickstart/


On Sat, Jul 13, 2013 at 12:37 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:

> Yes, I've just seen that, but it does not compile the regular expressions,
> meaning that would be slow would it not?
>
>
> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>
>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>
>> Also, for your use case, it's not a good idea. It's better to have just
>> one URL for a given page, with a redirect from possible variants. And
>> that's what Flask does by default.
>>
>>   S.
>>
>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>
>> Hi!
>>
>> I want to use regular expressions in flask URLS.
>>
>> For example:
>>
>> @app.route(r'/')
>> @app.route(r'/index/?')
>> def index():...
>>
>> I want it so that, it does not matter if you have localhost:8080/index
>> or localhost:8080/index/. How do I do this?
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>>
>> --
>> Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier-
>> http://linkedin.com/in/sfermigier
>> Founder & CEO, Abilian - Enterprise Social Software -
>> http://www.abilian.com/
>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>> Co-Founder and Chairman, Free&OSS Cluster -
>> http://www.gt-logiciel-libre.org/
>> Co-Founder & Vice-President, National Council for Free&OSS -
>> http://cnll.fr/
>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>> "Well done is better than well said." - Benjamin Franklin
>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>
>>
>
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>



-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Regular expressions in flask urls

From:
Gamesbrainiac
Date:
2013-07-13 @ 10:50
Merci Beacoup Phillipe.


On 13 July 2013 16:47, Philippe NDIAYE <phndiaye@gmail.com> wrote:

> In terms of speed, i really can't answer. But if i understand what you
> want to do, i know Flask can do it all for you with variables rules.
> For example, assuming you want to get the settings page of user, your url
> can't be constant because you have many users.
> So, with Flask you can do it like that:
>
>   @app.route('/<username>/settings')
>     def show_user_settings(username):
>     # What you wan't to do on this page.
>
> See the Variable Rules part of the quickstart for more informations:
> http://flask.pocoo.org/docs/quickstart/
>
>
> On Sat, Jul 13, 2013 at 12:37 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:
>
>> Yes, I've just seen that, but it does not compile the regular
>> expressions, meaning that would be slow would it not?
>>
>>
>> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>>
>>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>>
>>> Also, for your use case, it's not a good idea. It's better to have just
>>> one URL for a given page, with a redirect from possible variants. And
>>> that's what Flask does by default.
>>>
>>>   S.
>>>
>>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>>
>>> Hi!
>>>
>>> I want to use regular expressions in flask URLS.
>>>
>>> For example:
>>>
>>> @app.route(r'/')
>>> @app.route(r'/index/?')
>>> def index():...
>>>
>>> I want it so that, it does not matter if you have localhost:8080/index
>>> or localhost:8080/index/. How do I do this?
>>>
>>> --
>>> Kind Regards,
>>>
>>> Quazi Nafiul Islam
>>>
>>>
>>> --
>>> Stefane Fermigier - http://fermigier.com/ -
>>> http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
>>> Founder & CEO, Abilian - Enterprise Social Software -
>>> http://www.abilian.com/
>>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>>> Co-Founder and Chairman, Free&OSS Cluster -
>>> http://www.gt-logiciel-libre.org/
>>> Co-Founder & Vice-President, National Council for Free&OSS -
>>> http://cnll.fr/
>>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>>> "Well done is better than well said." - Benjamin Franklin
>>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>>
>>>
>>
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>
>
>
> --
> Regards,
> *
> *
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux Sysadmin  & Python programmer
>



-- 
Kind Regards,

Quazi Nafiul Islam

Re: [flask] Regular expressions in flask urls

From:
Philippe Ndiaye
Date:
2013-07-13 @ 11:04
Oh you speak french :)
De rien.


On Sat, Jul 13, 2013 at 12:50 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:

> Merci Beacoup Phillipe.
>
>
> On 13 July 2013 16:47, Philippe NDIAYE <phndiaye@gmail.com> wrote:
>
>> In terms of speed, i really can't answer. But if i understand what you
>> want to do, i know Flask can do it all for you with variables rules.
>> For example, assuming you want to get the settings page of user, your url
>> can't be constant because you have many users.
>> So, with Flask you can do it like that:
>>
>>   @app.route('/<username>/settings')
>>     def show_user_settings(username):
>>     # What you wan't to do on this page.
>>
>> See the Variable Rules part of the quickstart for more informations:
>> http://flask.pocoo.org/docs/quickstart/
>>
>>
>> On Sat, Jul 13, 2013 at 12:37 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:
>>
>>> Yes, I've just seen that, but it does not compile the regular
>>> expressions, meaning that would be slow would it not?
>>>
>>>
>>> On 13 July 2013 16:32, Stefane Fermigier <sfermigier@abilian.com> wrote:
>>>
>>>> https://www.google.com/search?q=regular+expressions+in+flask+URLS
>>>>
>>>> Also, for your use case, it's not a good idea. It's better to have just
>>>> one URL for a given page, with a redirect from possible variants. And
>>>> that's what Flask does by default.
>>>>
>>>>   S.
>>>>
>>>> On Jul 13, 2013, at 12:22 PM, Gamesbrainiac wrote:
>>>>
>>>> Hi!
>>>>
>>>> I want to use regular expressions in flask URLS.
>>>>
>>>> For example:
>>>>
>>>> @app.route(r'/')
>>>> @app.route(r'/index/?')
>>>> def index():...
>>>>
>>>> I want it so that, it does not matter if you have localhost:8080/index
>>>> or localhost:8080/index/. How do I do this?
>>>>
>>>> --
>>>> Kind Regards,
>>>>
>>>> Quazi Nafiul Islam
>>>>
>>>>
>>>> --
>>>> Stefane Fermigier - http://fermigier.com/ -
>>>> http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
>>>> Founder & CEO, Abilian - Enterprise Social Software -
>>>> http://www.abilian.com/
>>>> Founder & Board Member, Nuxeo - Open Source ECM - http://www.nuxeo.com/
>>>> Co-Founder and Chairman, Free&OSS Cluster -
>>>> http://www.gt-logiciel-libre.org/
>>>> Co-Founder & Vice-President, National Council for Free&OSS -
>>>> http://cnll.fr/
>>>> Vice President, Open World Forum 2013 - http://openworldforum.org/
>>>> "Well done is better than well said." - Benjamin Franklin
>>>> "There's no such thing as can't. You always have a choice." - Ken Gor
>>>>
>>>>
>>>
>>>
>>> --
>>> Kind Regards,
>>>
>>> Quazi Nafiul Islam
>>>
>>
>>
>>
>> --
>> Regards,
>> *
>> *
>> *Philippe Thécou NDIAYE*
>> IT Student @ SUPINFO Lyon
>> Linux Sysadmin  & Python programmer
>>
>
>
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>



-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Regular expressions in flask urls

From:
Philippe Ndiaye
Date:
2013-07-13 @ 10:30
You don't need to do a regular expression. Just set your route like that:

    @app.route('/index/')

This will work with both  localhost:8080/index and
localhost:8080/index/because Flask will automagically add the trailing
slash to the end if it's
not done.


On Sat, Jul 13, 2013 at 12:22 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:

> Hi!
>
> I want to use regular expressions in flask URLS.
>
> For example:
>
> @app.route(r'/')
> @app.route(r'/index/?')
> def index():...
>
> I want it so that, it does not matter if you have localhost:8080/index or
> localhost:8080/index/. How do I do this?
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>



-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Regular expressions in flask urls

From:
Gamesbrainiac
Date:
2013-07-13 @ 10:34
But what if I wanted to use regex? For something
like<regex_here>-<account_name>,
something like that.


On 13 July 2013 16:30, Philippe NDIAYE <phndiaye@gmail.com> wrote:

> You don't need to do a regular expression. Just set your route like that:
>
>     @app.route('/index/')
>
> This will work with both  localhost:8080/index and 
localhost:8080/index/because Flask will automagically add the trailing 
slash to the end if it's
> not done.
>
>
> On Sat, Jul 13, 2013 at 12:22 PM, Gamesbrainiac <gamesbrainiac@gmail.com>wrote:
>
>> Hi!
>>
>> I want to use regular expressions in flask URLS.
>>
>> For example:
>>
>> @app.route(r'/')
>> @app.route(r'/index/?')
>> def index():...
>>
>> I want it so that, it does not matter if you have localhost:8080/index
>> or localhost:8080/index/. How do I do this?
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>
>
>
> --
> Regards,
> *
> *
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux Sysadmin  & Python programmer
>



-- 
Kind Regards,

Quazi Nafiul Islam