In a Django template how do I remove the first Zero from all the this mobile numbers I’m displaying. In Python I have tried this but with no success….
{% for object in data %}
{{ object.mobile.lstrip('0') }}
{% endfor %}
views.py
def sms(request, incentive):
objectQuerySet = Recipient.objects.filter(incentiveid=incentive)
context = {'data':objectQuerySet}
return render_to_response('smssend.html', context, context_instance=RequestContext(request))
You should pass your data to your template in the correct format. Django templates are not “Python interspersed with HTML” like PHP is.
For example, when you first pass your
datain your view, you should make sure that it is an iterable with the zeroes already stripped.There is no
lstripin the Django template mini-language.Edit: If you know that the first digit will always be a 0, you can also do this: