我知道您可以使用fetch API将数据从前端发送到后端,以便由django视图处理。我也知道你可以使用jQuery应用程序接口来做“数据获取”。
我想知道是否有任何其他常用的方法,只使用Javascript发送数据从前面到后面,而不使用fetch API或jQuery Ajax。
发布于 2021-04-01 08:56:06
我在使用URL之前已经做到了这一点。
包括如下内容:
var binform = document.createElement('form');
binform.setAttribute('method','POST');
binform.setAttribute('action',`/unfollow/${data[i].crypto}/`);在我的javascript中,从一个抓取请求中获取该值并将该值传递给view函数。
@csrf_exempt
def deletecrypto(request, crypto):
if request.method == "POST":
user = request.user
usercurr = User.objects.filter(username=user).first()
userid = usercurr.id
profilepic = ProfilePic.objects.filter(user=user).first()
usr = request.user.username
following = FollowedCrypto.objects.filter(user=user.id)
cryptos = []
for i in following:
cryptos.append(i.cryptocurrency)
if crypto in cryptos:
newfollow = FollowedCrypto.objects.filter(user=user,
cryptocurrency=crypto).delete()
return render(request,"PlanetCrypton/profile.html",{
"following":following,
"crypto": cryptos,
"user": user,
"usr" : userid,
})这就是我如何设法删除,并在另一个功能中,添加到我的模型中的加密货币。
https://stackoverflow.com/questions/66775080
复制相似问题