the function to be implemented is that when viewing a resource, you need to deduct the points of the resource, display the real resource address, and call ajax, to implement no refresh
. models.py
class Zyuser_MeiMei (models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
mmei = models.ForeignKey("MeiMei", verbose_name="", null=True)
mark = models.BooleanField(default =False, verbose_name=_(u""))
def __unicode__(self):
return self.author.username
class Meta:
verbose_name_plural = u"vip"
views.py
< H1 > users view deduction function < / H1 > @ login_required
@ csrf_exempt
def look_mm (request, mm_id):
author = request.user
mm = MeiMei.objects.get(id = mm_id)
print "adsfasdf"
if author.levels < mm.level:
-sharpraise ","
-sharp!
return render(request,"meimei/jifen.html")
else:
User.objects.filter(username = author.username).update(levels=F("levels") - mm.level)
u_m = Zyuser_MeiMei.objects.update_or_create(author=author, mmei=mm)
u_m.mark = True
print "aaaaaaaaaa"
return u_m
.html page
< script src= " http://libs.baidu.com/jquery/.;></script>
< script type= "text/javascript" >
function vip_chakan (o, meimei.id) {
$.ajax({
type:"POST",
url:"/look_mm/"+{{meimei.id}}+"/",
dataType:"json",
processData:false, // jquery
contentType:false, // jquery
success:function(u_m){
alert(u_m.mark);
}
error:function(){
alert("!")
}
});
}
< / script >
url.py
url (r"^ look _ mm/ (? P < mm_id > [0-9] +) / $", login_required (look_mm), name="lookmm"),
I don"t know what went wrong. Which views.py function is always not executed?