Mario, you already got a good answer, but I added another way you could do it by using route predicates.
https://gist.github.com/marioidival/60a2a06730947cc32b00 On Wednesday, March 4, 2015 at 10:08:59 PM UTC-5, Mário Idival wrote: > > Blaise, How do you would using @view_defaults and @view_config nested? > Sorry, I forgot to mention it. > > https://gist.github.com/marioidival/60a2a06730947cc32b00 > > > Mário Idival > Python Developer > > *Twitter|Github|Skype *: *marioidival* > *Facebook*: *mario.idival* > *User Linux** : **#554446* > > 2015-03-04 17:41 GMT-03:00 Blaise Laflamme <[email protected] > <javascript:>>: > >> to me >> >> /users >> /users/{user_id} >> /user or /me >> >> are all different endpoints and need different routes and different route >> names related to actions. >> >> /user/{user_id} looks weird to me, I would expect collections to have >> plural names like /users (except some grammatical exceptions). >> >> I would use something like: >> >> /users >> GET: route_name='users.list' >> POST: route_name='users.create' >> >> /users/{user_id} >> GET: route_name='users.read' >> POST/PUT: route_name='users.update' >> DELETE: route_name='users.delete' >> >> On Wednesday, March 4, 2015 at 2:47:12 PM UTC-5, Mário Idival wrote: >>> >>> ... >>> >>> I had to create another route to catch a specific User >>> >>> config.add_route("users", '/user/') >>> config.add_route("user_details", '/user/{user_id}') >>> >>> >>> Mário Idival >>> Python Developer >>> >>> *Twitter|Github|Skype *: *marioidival* >>> *Facebook*: *mario.idival* >>> *User Linux** : **#554446* >>> >>> 2015-03-04 16:45 GMT-03:00 Mário Idival <[email protected]>: >>> >>>> I am writing a tutorial, "Creating REST API with Pyramid - free >>>> dependencies", and arrived at a point where the GET request should get a >>>> list of users and a specific user... >>>> >>>> /users/ >>>> /users/{user_id} >>>> >>>> Mário Idival >>>> Python Developer >>>> >>>> *Twitter|Github|Skype *: *marioidival* >>>> *Facebook*: *mario.idival* >>>> *User Linux** : **#554446* >>>> >>>> 2015-03-04 14:52 GMT-03:00 Chris McDonough <[email protected]>: >>>> >>>> On 03/04/2015 11:03 AM, Jonathan Vanasco wrote: >>>>> >>>>>> >>>>>> >>>>>> On Wednesday, March 4, 2015 at 10:30:44 AM UTC-5, Oliver Berger wrote: >>>>>> >>>>>> If you want the same view executed for several urls just decorate >>>>>> it >>>>>> twice with a different route... >>>>>> >>>>>> >>>>>> +1 >>>>>> >>>>>> That's what most people would do. >>>>>> >>>>>> it would look something like this: >>>>>> >>>>>> config.add_route ('test_index', '/ test /') >>>>>> config.add_route ('test_focus', '/ test / {test_id}') >>>>>> >>>>>> class MyViews(object): >>>>>> @view_config("test_index") >>>>>> @view_config("test_focus") >>>>>> def test_unified(self): >>>>>> pass >>>>>> >>>>> >>>>> >>>>> To be pedantic... >>>>> >>>>> class MyViews(object): >>>>> @view_config(route_name="test_index") >>>>> @view_config(route_name="test_focus") >>>>> def test_unified(self): >>>>> pass >>>>> >>>>> (requires 'route_name=' keyword arg to work properly). >>>>> >>>>> - C >>>>> >>>>> >>>>> >>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "pylons-discuss" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>>> an email to [email protected] >>>>>> <mailto:[email protected]>. >>>>>> To post to this group, send email to [email protected] >>>>>> <mailto:[email protected]>. >>>>>> Visit this group at http://groups.google.com/group/pylons-discuss. >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "pylons-discuss" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To post to this group, send email to [email protected]. >>>>> Visit this group at http://groups.google.com/group/pylons-discuss. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "pylons-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at http://groups.google.com/group/pylons-discuss. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
