English 中文(简体)
Pylons routing through cellers
原标题:Pylons routing through folders

我是新到的,我的任务是设计一个模拟版本系统。 我想以不同的文件夹储存各种版本的APIC。 例如:

controllers/APIVersion/v1/clientAPI.py -- Version 1
controllers/APIVersion/v2/clientAPI.py -- Version 2
controllers/APIVersion/v3/clientAPI.py -- Version 3

要求获得这些预报信息的请求应如此:

curl  http://mySite/v1/clientAPI/get/  -- Should bring me to the first version
curl  http://mySite/v2/clientAPI/get/  -- Should bring me to the second version

我知道,我可以通过路线这样做。 py. 这是我的第一个想法。

map.connect( /APIVersion/{version}/{controller}/{action} )

关于如何前往预期地点的想法? 此外,我感到可以自由评论我的版本方法。 我欢迎这一建议。

问题回答

The first thing Routes sees is the URL (which is also the first argument to connect). You re trying to access the API using URLs like /v1/clientAPI/get/ but you ve configured your routing.py with routes like /APIVersion/{version}/{controller}/{action}. So there s no match.
The simplest "fix" would be use URLs like http://mySite/APIVersion/v1/clientAPI/get/ for v1 or http://mySite/APIVersion/v2/clientAPI/get/ for v2 and so on (you ll also need to make sure that APIVersion & all v1 to vX are packages + the controller class in each clientAPI.py is called ClientapiController).
If that s not an option (as in you still want to use URLs like /v1/clientAPI/get/ but have the controllers directory layout like /APIVersion/v1/clientAPI/get/) than you ll need to use a method similar to the one listed here.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签