が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
ことの一つは、あなたがURLにPOSTを作るか、それをロードする場合は、別のものを作ることです。
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(...)
ビューがちょうどロードされたか、またはPOSTを受け取った場合、異なることをする必要がある場合は、2 render_to_response
があります。
は、私は2番目ます(ドキュメントはあなたが行うのに役立ちます)HTMLを自分で書きたい場合でも、Djangoのフォームを使用して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形式を使用している
私がrequest.POST ['my_options']を行う場合、このエラーが発生します:リストインデックスが範囲外です。 – avatar