我正在尝试发送post请求到我的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。提前感谢
发布于 2017-06-05 12:57:14
我建议在Django中从安卓应用程序等其他来源进行Framework.You调用,最好使用Rest,在Django的情况下,尝试使用Django Rest API可以从这个Tutorial开始
https://stackoverflow.com/questions/44361808
复制相似问题