![](/img/trans.png)
[英]Optimizing CSV file processing in POST request (Django Rest Framework)
[英]Processing POST request in Django
嗨,我有一個簡單的POST請求表單,當我只有一個輸入但沒有兩個輸入時,它就可以工作。 有人可以給我一些啟發嗎?
的index.html
<form name="input" action="{% url 'sending' %}" method="post">
{% csrf_token %}
Recipient: <input type="text" name="recipient">
<br>
Message: <input type="text" name="content">
<br>
<input type="submit">
</form>
views.py
def sending(request):
recipient = request.POST.get('recipient','')
content = request.POST.get('content','') #not working when I am doing this...
someMethod(recipient, content)
return HttpResponseRedirect(reverse('results'))
在您的設置中添加“表單”部分將極大地幫助您...在此處查看表單上的快速入門文檔: https : //docs.djangoproject.com/en/1.6/topics/forms/
特別是,請檢查“在視圖中使用表單”: https : //docs.djangoproject.com/en/1.6/topics/forms/#using-a-form-in-a-view
基本上,您最終得到一個“ forms.py”文件,該文件定義了表單字段。 然后,在完成所有過程之后,您將在表單字段中獲得一個簡單的API,如下所示:
form.cleaned_data['recipient']
form.cleaned_data['content']
等等
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.