通過POST管理數據
def yourView(request):
# Use '.get('id', None)' in case you don't receive it, avoid getting error
selected_option = request.POST.get('my_options', None)
if selected_option:
# Do what you need with the variable
一兩件事,可能是與Django表單有用的是使不同的東西,如果你做一個POST到URL或只是加載:
def yourView(request):
if request.POST: # If this is true, the view received POST
selected_option = request.POST.get('my_options', None)
if selected_option:
# Do what you need to do with the variables
return render_to_response(...)
return render_to_response(...)
有2 render_to_response
萬一你需要做不同的事情,如果視圖剛剛加載或接收POST。
通過GET
def yourView(request):
# Use '.get('id', None)' in case you don't receive it, avoid getting error
selected_option = request.GET.get('my_options', None)
if selected_option:
# Do what you need with the variable
管理數據我第二次使用Django表單,即使你要自己編寫HTML(該文檔會幫你做)。 – 2011-01-24 20:12:42
在這種情況下,這將是使用Django的形式