【发布时间】:2017-06-05 04:45:31
【问题描述】:
我正在尝试从我的 django APi 发送发布请求,但它没有给出任何错误,它工作正常,但 django 仍然没有收到任何数据。 我的观点是这样的。
def add(request):
if request.method == "POST":
form = bookForm(request.POST)
if form.is_valid():
data = form.save(commit=False)
data.save()
return redirect('/books')
else:
form = bookForm
return render(request, 'book_edit.html', {'form': form})
而我的Http post方法是。
try{
Log.w("this","Started");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://vidu171.pythonanywhere.com/books/add");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("title", params[0]));
nameValuePairs.add(new BasicNameValuePair("author","vidu"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.w("htt response",response.toString());
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
我已经允许表单的网址是 http://vidu171.pythonanywhere.com/books/add 。提前致谢
【问题讨论】:
标签: android django forms http-post