-1

我认为它起源于这个视图,因为它正在被转移到主视图(见下文):

@login_required
def HomePage(request):
    if request.user.get_profile().phone == "":
        return HttpResponseRedirect('/phone')
    else:
        add_list = add.objects.all()
        ctx = {'last_login':request.session.get('social_auth_login_backend')}
        return render_to_response("homepage.html", {'add_list': add_list, 'ctx':ctx}, context_instance=RequestContext(request))

和模型:

class customuser(models.Model):
    last_login = models.DateTimeField(blank=True, null=True)
    is_active = models.BooleanField()
    nickname = models.CharField(max_length=255)
    regdate = models.DateField(auto_now=True)
    phone = models.CharField(max_length=255)
    user = models.OneToOneField(User)
    city = models.ForeignKey(locations, null=True)

    def __str__(self):
        return "%s user " % self.user

    def create_user_profile(sender, instance, created, **kwargs):
        if created:
            profile, created = customuser.objects.get_or_create(user=instance)

    post_save.connect(create_user_profile, sender=User)

    class Admin:
        pass    
4

1 回答 1

0

我不确定这是否是您出现问题的原因,但是您传递给模板的上下文字典看起来不对。该视图可能应该被重写 -

def HomePage(request):
    if request.user.get_profile().phone == "":
        return HttpResponseRedirect('/phone')
    else:
        ctx = {'last_login':request.session.get('social_auth_login_backend'),
               'add_list': add.objects.all()}
        return render(request, "homepage.html", ctx)
于 2013-03-03T22:24:15.473 回答