社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

user10997785user10997785

user10997785user10997785 最近创建的主题
user10997785user10997785 最近回复了
6 年前
回复了 user10997785user10997785 创建的主题 » 如何从Ionic4到DjangorestFramework执行post请求(带数据)

我不太熟悉djano是如何工作的,但是如果你想从post请求中得到响应,你需要返回 httpClient.post() 是的。请记住从rxjs包导入map。

import { tap, map } from 'rxjs/operators';
.
.
get_form_data(){
  const httpOptions = {
    headers: new HttpHeaders({
      'Content-Type':  'application/json',
      'Authorization': 'Basic ' + btoa('myusername:mypassword')
    })
  } 

  const request =  {   
    "item_title": this.title,
    "item_description": this.desc,
    "item_price": this.price,
    "item_price_later": false,
    "item_action": this.action,
    "item_color": this.color,
    "item_category": this.category,
    "item_type": this.type,
    "item_size": this.size,
    "item_city": this.city,
    "item_phone": this.phone,
    "item_image_1": "https://fostania-aws-bucket.s3.amazonaws.com/media/media/Jellyfish.jpg",
    "item_image_2": null,
    "item_image_3": null,
  }
  return this.httpClient.post('https://www.fostania.com/api/items/create/',request, httpOptions) 
    .pipe(
      tap(data => console.log(data),
      //catchError(error => console.log(error)
)}