If you are using Django, there is django-mobile module which allows you to check the mobile usage in the template like this:
{% if flavour != "mobile" %}Desktop version{% endif %}
If you are not using Django, you can still analyze the source of that module and implement something similar for your website.