2
假設你有一個使用post和get方法的網頁,你寫了下面的觀點來生成它:Django的觀點:良好的編程習慣問題
def homepage(request):
if 'login' in request.POST:
# ......... code goes here, and you return an appropriate response
if 'register' in request.POST:
# ......... code goes here, and you return an appropriate response
# When no Post request, just render the page
return render_to_response('homepage.html')
問:
是它認爲好的編程實踐將上述視圖分成三個視圖:一個用於登錄,一個用於註冊,另一個用於顯示頁面?或者可以保持原樣。
編輯
在上面列出的情況下,如果服務器收到一個「GET」我不檢查。但這個想法仍然是相同的:)
一個更好的主意。這分開了永遠是好事的邏輯。 – Jake 2011-03-15 02:14:00
是的,我正在考慮做這樣的事情,因爲在一個視圖中使所有的代碼看起來「麻煩」和「笨拙」。感謝您的答覆 :) – 2011-03-15 02:32:03