int()的基数为10的无效文字:“john”

时间:2015-02-17 15:51:13

标签: python django

这是我的views.py

def get_contacts(request):

    context = RequestContext(request)
    contact_list = []

    name=None

    if request.user.is_authenticated():
        name=request.user.username

    contact_list = contact.objects.filter(user=name).values_list('friend',flat=True)

    friend_list=simplejson.dumps(list(contact_list))

    return HttpResponse(friend_list,mimetype="application/json")

这是我的models.py

from django.db import models

from django.contrib.auth.models import User

class UserProfile(models.Model):

    user = models.OneToOneField(User)

    picture = models.ImageField(upload_to='profile_images', blank=True)

    def __unicode__(self):

        return unicode(self.user.username)

这是我的错误,当我试图致电get_contact_list

ValueError: invalid literal for int() with base 10: 'John'

1 个答案:

答案 0 :(得分:0)

您无法使用名称过滤用户列。而不是

contact.objects.filter(user=name)...

contact.objects.filter(user__username=name)...