Answer the question
In order to leave comments, you need to log in
How to hide the last digits of a phone number taken from the database on the server side?
I have phone numbers stored in a database in text format. When displaying them on the page, you need to hide the last two digits behind an asterisk, it is important to do this from the server side so that it is not possible to somehow parse or see the html code in the browser.
model.py
class DailyOrders(models.Model):
phone = models.CharField(max_length=25, verbose_name='Номер телефона')
name_of_client = models.CharField(max_length=100, blank=True, null=True, verbose_name='Имя')
class QuickOrdersPage(ListView):
model = DailyOrders
template_name = 'Catalog/quick_orders.html'
context_object_name = 'orders'
allow_empty = True
paginate_by = 10
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
def hide_phone(self):
allOrders = DailyOrders.objects.all()
for oneOrder in allOrders:
clientPhone = oneOrder.phone
clientPhone = clientPhone[:-2]
clientPhone += '**'
return clientPhone
context['clientPhone'] = hide_phone(self)
return context
{% for order in orders%}
<div class="modal-quick__row">
<div class="modal-quick__column first__column">
<div class="modal-quick__title">Имя собственника:</div>
</div>
<div class="modal-quick__column second__column">
<div class="modal-quick__text">{{order.name_of_client}}</div>
</div>
</div>
<div class="modal-quick__row">
<div class="modal-quick__column first__column">
<div class="modal-quick__title">Телефон:</div>
</div>
<div class="modal-quick__column second__column">
<div class="modal-quick__text" id="client__phone">{{clientPhone}}</div>
</div>
</div>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question