這是非常具體的什麼,我試圖這樣做,我開始描述它是什麼:使用查詢字符串
- 金字塔應用中投放情節像http://localhost:6543/path/to/myplot/plot001.png
- 如果情節不可用另一個圖像被提供(work.png)
- 另一部分是變形視圖,它提供了一個HTML表單來輸入配置,例如:http://localhost:6543/path/to/myplot/plot001.png?action=edit。請注意查詢字符串「action = edit」。
- 配置由數據文件,模板等組成
- 窗體具有save(保存配置)和渲染按鈕(http:// localhost:6543/path/to/myplot/plot001.png?action = render )。將結果呈現爲一個png文件,然後以靜態方式使用。
我想出了所有使用Matplotlib等渲染的東西,但我是Pyramid和Deform的新手。我也有一個工作視圖,用於從文件中提供圖表。變形也是一種作品。目前我還不清楚如何最好地構建ULR來區分服務,編輯和呈現用例。我猜在金字塔這裏說這意味着如何配置serve_view和edit_view的路由。
__init__.py:
config.add_route('serve_route',
'/{project_name}/testruns/{testrun_name}/plots/{plot_name}.png')
config.add_route('edit_route',
'/{project_name}/testruns/{testrun_name}/plots/{plot_name}.png')
# can I use query strings like "?action=edit" here to distinguish the difference?
views.py:
@view_config(context=Root, route_name='serve_route')
def plot_view(context, request):
...
@view_config(context=Root, renderer='bunseki:templates/form.pt', route_name='edit_route')
def edit_view(request):
...
我金字塔手冊我找不到參考如何在路線中設置參數。我想一個指向一些文檔或樣本的指針就足夠了,我可以自己弄清楚細節。謝謝!
金字塔有他們稱之爲Multidict的機制。我認爲這是訪問查詢字符串的方式。我將合併兩個視圖的情節和編輯成一個,並使用如下所示的區別: if request.GET.getall('action')中的'編輯': #編輯配置 – mark
你在說什麼上面的評論是好的,這可能是我會這樣做的方式;您可以將自定義謂詞交替添加到add_route語句中,以便匹配查詢字符串中的兩個路由。請參閱http://docs.pylonsproject.org/projects/pyramid/1.1/narr/urldispatch.html#custom-route-predicates –