私はapp.pyという名前のシンプルなTurboGearsの2スクリプトを、持っている: "!こんにちは、世界を" 私はapp.pyを実行し、http://localhost:5000/all__thingsを訪れたとき、私は見TurboGearsはURLのどの文字を置き換えますか?
#!/usr/bin/env python3
from wsgiref.simple_server import make_server
from tg import expose, TGController, AppConfig
class RootController(TGController):
@expose()
def all__things(self):
return "Hello world!"
config = AppConfig(minimal=True, root_controller=RootController())
print("Serving on port 5000...")
httpd = make_server('', 5000, config.make_wsgi_app())
httpd.serve_forever()
を予想通り。しかし、これらのURLも動作:
http://localhost:5000/all--things
http://localhost:5000/[email protected]@things
http://localhost:5000/all$$things
http://localhost:5000/all++things
http://localhost:5000/all..things
http://localhost:5000/all,,things
ならびにそれらの組み合わせ:
http://localhost:5000/all-_things
http://localhost:5000/all_-things
http://localhost:5000/[email protected]
http://localhost:5000/[email protected]
http://localhost:5000/[email protected]
http://localhost:5000/[email protected]$things
エトセトラ... TurboGearsのにアンダースコアに置換することができる文字の完全なリストは何
URL?
また、この機能を特定の文字に置き換えるように制限できますか?理想的には、ダッシュ(http://localhost:5000/all--things)付きのURLを動作させ、アンダースコア(http://localhost:5000/all__things)または他の奇妙な文字を含むURLは機能しません。
'config.dispatch_path_translator = False'を設定するとプログラムがクラッシュしますが、' config.dispatch_path_translator = None'は動作します。最後に私は決めました: 'config.dispatch_path_translator = lambda path_piece:path_piece.replace( ' - '、 '_')path_piece以外の場合 '' ' ありがとうございました。 –
ああ、申し訳ありません、それは真/なし/機能です 私は真の反対として反射で偽を書いた:D 答えを更新しました – amol