I applied a template filter that retrieves a domain from an email address. In the template file, I have this code:
{% for email in user_list %}
<p>
{{email.email}} corresponds to this domain:
<b> {{email.email|domain}} </b>
</p>
{% endfor %}
Currently, bold domain names are highlighted. What I want to do is to make bold ONLY these email addresses with a "valid" email extension (for example, only in the @ gmail.com domain). How to apply if or ifequal statement for this?
For example, this is the logic I want to have -
{% for email in user_list %}
<p>
{{email.email}} corresponds to this domain:
{% if domain = 'specified extension' %}
<b> {{email.email|domain}} </b>
{% else %}
{{ email.email|domain }}
{% endif %}
</p>
{% endfor %}
Update:
OK. I got this working by creating a custom model in models.py, for example:
class Table(models.Model):
name = models.CharField(max_length=50)
email = models.CharField(max_length=50)
def valid_email(self):
verified = ['yahoo.com','gmail.com']
domain = self.email.split('@')[1]
return domain in verified
And in the template index.html-
{% for email in user_list %}
<p>
{{email.email}} corresponds to this domain:
{% if email.valid_email %}
<b>{{ email.email|domain}}</b>
{% else %}
{{ email.email|domain}}
{% endif %}
</p>
{% endfor %}
, , models.py . valid_emails(), ? ( )? .