user2106353
user2106353

Reputation: 1249

Check some part of string in variable in template Django

Hi i got the site domain in the template name with the

{{request.META.HTTP_HOST}}

from which i got the value some thing like this

pydev.aviesta.com

and

pydev.aviesta.com.mx

i need to show different data for both domains but as this is the dev server i cant use the full doamin name for compare can i check only .mx or .com so there will be no problem when going to live site

Upvotes: 1

Views: 203

Answers (2)

user2106353
user2106353

Reputation: 1249

i got the solution with js

<script>
 var str = location.host;
        if( str.search(".mx") > 0 ){
        var dom = 'mx';
        }else{
        var dom = 'com';
        } </script>

Upvotes: 0

Ahsan
Ahsan

Reputation: 11832

You may need Custom filter for this.

@register.filter(name='split')
def split(value, arg):
    return value.split('.')[-1]

Use it as {{request.META.HTTP_HOST|split}}

Upvotes: 1

Related Questions