私はdjangoを使用しています。私はこのデコレータを書いて、Ajaxビューのために見つけた繰り返しコードを取り除きました。あなたの意見を知りたい(あまりにも基本的で、悪いデザイン、代わりにこれを試してみてください。これは良いpythonデザインですか?
def ajax_only(func):
def _ajax_only(request,*args,**kwargs):
if not request.is_ajax():
return HttpResponse('<p>Ajax not supported.</p>')
else:
return func(request,*args,**kwargs)
return _ajax_only
これはhttp://s.tk/reviewのより良い質問です。 –