【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>""")

 

posted @ 2021-03-26 23:13  PythonNew_Mr.Wang  Views(399)  Comments(0)    收藏  举报