I just want to know how to create URL pattern in routes.py, what i really
want to understand is, how to parse parameters in URL patterns like the
one, Massimo showed in his example --
*('/article/(?P<id>\d+)' , '/appname/default/article/$id')*
*(?P<id>\d+) *
*
*
I would be really helpful if I could get any references.
Deepak
On Thursday, 16 August 2012 22:48:10 UTC+5:30, Massimo Di Pierro wrote:
>
> I would recommend Anthony's solution but you can do something similar like
> this:
>
> 1) create a file routes.py with
> # ---- begin ----
> routes_in = [
> ('/' , '/appname/default/api_root'),
> ('/articles' , '/appname/default/api_articles'),
> ('/article/(?P<id>\d+)' , '/appname/default/article/$id')]
>
> routes_out=[(b,a) for (a,b) in routes_in]
> # --- end ---
>
> then in your default.py controller you can do:
>
> def api_root():
> return 'Welcome'
>
> def api_articles():
> return 'List of ' + URL('api_articles')
>
> def api_article():
> articleid = request.args(0,cast=int)
> return 'You are reading ' + articleid
>
> you can also do
>
> @request.restful
> def api_article():
> def GET(articleid):
> return 'You are reading ' + articleid
> return locals()
>
>
> Massimo
>
> On Thursday, 16 August 2012 04:05:21 UTC-5, deepak wrote:
>>
>> I would like to perform REST Services by mapping url to the
>> controller-function. For eg:
>>
>> @app.route('/')def api_root():
>> return 'Welcome'
>> @app.route('/articles')def api_articles():
>> return 'List of ' + url_for('api_articles')
>> @app.route('/articles/<articleid>')def api_article(articleid):
>> return 'You are reading ' + articleid
>>
>> which could be done in Flask. Basically i would want to match the URLs to
>> the service in web2py.
>>
>> On Tuesday, 14 August 2012 23:43:20 UTC+5:30, Anthony wrote:
>>>
>>> It looks like you could do all of that with web2py. Can you be more
>>> specific regarding how you want your URLs to look and what they should
>>> retrieve. In addition to RESTful services and routing, have you looked at
>>> the basics: http://web2py.com/books/default/chapter/29/4#Dispatching?
>>>
>>> Anthony
>>>
>>> On Tuesday, August 14, 2012 1:10:58 PM UTC-4, deepak wrote:
>>>>
>>>> I want to use RESTful URL patters likewise in Flask, '
>>>> http://publish.luisrei.com/articles/flaskrest.html'
>>>>>
>>>>> All I could end up finding was to make use of routes.py [routes_in &
>>>> routes_out].
>>>>
>>>> Deepak
>>>>
>>>
--