2014-04-06 22 views
0
def check(request): 
     if request.user.is_authenticated: 
     uid = request.user.id 
     if AllUsers.objects.get(FK_id = uid): 
      return True 
     else: 
      return False 

错误:在DoesNotExist /用户/ AllUsers的匹配查询不存在的。通过ID得到的是在Django /夹层产生错误

如何解决这个错误?

UPDATE: * 型号: *

from django.db import models 
from django.contrib.auth.models import User 
from mezzanine.pages.models import Page 
# The members of Page will be inherited by the Author model, such 
# as title, slug, etc. For authors we can use the title field to 
# store the author's name. For our model definition, we just add 
# any extra fields that aren't part of the Page model, in this 
# case, date of birth. 

GENDER = (('male','Male'), ('female','Female')) 
class AllUsers(models.Model): 
    FullName = models.CharField(max_length=300) 
    DOB = models.DateField() 
    Gender = models.CharField(max_length=7, choices = GENDER) 
    HomeAddress = models.TextField() 
    Contact = models.CharField(max_length=300) 
    Email = models.EmailField() 
    FK = models.ForeignKey(User) 
+0

你能告诉我们你的AllUsers模型吗? –

+0

@MihaiZamfir查看更新 –

回答