使用django中的javascript变量更新数据库

时间:2015-07-13 16:21:30

标签: javascript python django

我正在测试简单的post方法来更新django db以使用js使用FB集成。我尝试了很多次但db没有得到更新

继承人view.py

    from django.shortcuts import render
    from django.utils import timezone
    from django.http import HttpResponse
    from .models import user

    def login_call(request):
    return render(request, 'login/login.html', {})

     def user_details(request):
     if request.method is POST:
        usrID=request.POST['FB_usrID']
        me=user.objects.filter(FB_usrID=usrID).values()
        if me== None :
            name=request.POST['FB_name']
            link=request.POST['FB_link']
            usrName=request.POST['FB_usrname']
            email=request.POST['FB_email']
            hello=user.objects.create(
                                      FB_name=name,
                                       FB_link=link,
                                      FB_usrname=usrName,
                                        FB_usrID=usrID,
                                        FB_email=email,
                               reg_date=timezone.now())
            hello.save()
            response = {
                 'status': 1,

            }
        else :
            response ={
                  'status':0,
            }
        return HttpResponse(response, mimetype='application/json')

heres model.py

        from django.db import models
        from django.utils import timezone

        class user(models.Model):
        FB_name=models.CharField(max_length=20)
        FB_link=models.URLField()
        FB_usrname=models.CharField(max_length=50)
        FB_usrID=models.IntegerField()
        FB_email=models.CharField(max_length=50)
        reg_date = models.DateTimeField(default=timezone.now)

而heres是邮政编码

function Login()
{
    $.post('index',{
        csrfmiddlewaretoken: '{{ csrf_token}}' ,
        FB_usrID:'554113199893',
        FB_name:'hello' ,
        FB_link:'ghtnnv.com',
        FB_usrname:'gdsbdjaud',
        FB_email:'thaskhsd@gmail.com',
    },
    function(data,status) {
        if(data.status == 1){
            document.getElementById("message").innerHTML +=  "<br>Sent";
        }
        else{
            document.getElementById("message").innerHTML +=  "<br>Fail";
        }
    });
}

0 个答案:

没有答案