【django基础】GET带参数与接口接收
# urls.py url('api/collection$', Collection.Collection.as_view()),
# Collection.py def get(self, request): title = request.GET.get("name") url = request.GET.get("url") message = {} try: models.Colect.objects.create(co_title=title,co_down_link=url) return HttpResponse("收藏成功") except Exception as e: print(e) return HttpResponse("收藏失败")
# 配合Admin: # admin.py def collection(self):
button_html = "<a href='/api/collection?name={}&url={}' >点击收藏</a>".format(self.name,self.down_link)
return format_html(button_html)
collection.short_description = format_html("""<a href='#' style="position: relative;left: -12px;">收藏</a>""")
Python全栈(后端、数据分析、脚本、爬虫、EXE客户端) / 前端(WEB,移动,H5) / Linux / SpringBoot / 机器学习