问题描述:

I'm sure there is something silly I'm missing here, but I'm trying to use ifequal to evaluate a template variable.

Here's my model:

USER_TYPES = (

('instructor', 'Instructor'),

('student', 'Student'),

)

class UserProfile(models.Model):

type = models.CharField(

choices=USER_TYPES, max_length=12

)

user = models.ForeignKey(

User,

unique=True

)

def __unicode__(self):

return u'%s' % (self.type)

...and I'm using this in the template:

{% ifequal user.userprofile_set.get student %}

You're a student!

{% endifequal %}

When I simply print out {{ user.userprofile_set.get }} I get:

student

Not sure what I'm missing - any help is appreciated!

网友答案:

ifequal is deprecated... but I think that this works:

{% ifequal user.userprofile_set.get.type "student" %}
    Your a student! 
{% endifequal %}
相关阅读:
Top