I had text in database on TextField. I am using this field in my template applying tag linebreaksbr but text displaying simple plain.
In console I have next result:
Out[60]: 'class UpdateAccountInfo(LoginRequiredMixin, View):\n """\n View for update information about account of user\n """\n\n def post(self, request, *args, **kwargs):\n if request.is_ajax():\n result = dict()\n status = 200\n try:\n if request.FILES:\n coordinates_x1 = int(request.POST.get(\'coordinates[x1]\'))\n coordinates_y1 = int(request.POST.get(\'coordinates[y1]\'))\n coordinates_x2 = int(request.POST.get(\'coordinates[x2]\'))\n coordinates_y2 = int(request.POST.get(\'coordinates[y2]\'))\n field = \'account_user_info-picture\'\n value = request.FILES[field]\n new = {field: value}\n account_info = AccountUserInfo.objects.get(account=self.request.user)\n account_info.picture = value\n account_info.full_clean()\n account_info.save()\n picture_file = Image.open(account_info.picture.path)\n cropped_picture = picture_file.crop([coordinates_x1, coordinates_y1, coordinates_x2, coordinates_y2])\n cropped_picture.save(account_info.picture.path)\n result[\'new_image_url\'] = account_info.picture.url\n else:\n field = self.request.POST[\'field\']\n value = self.request.POST[\'value\']\n if field == \'datetimepicker_for_birthday_account\':\n correct_field = \'birthday\'\n else:\n correct_field = field.replace(\'account_user_info-\', \'\')\n new = {correct_field: value}\n account_info = AccountUserInfo.objects.filter(account=self.request.user)\n AccountUserInfo(**new).full_clean(exclude=[\'account\'])\n account_info.update(**new)\n account_info = AccountUserInfo.objects.get(account=self.request.user)\n result[\'new_value_progresbar_filling_account_info\'] = account_info.filling_account_info()\n except BaseException as errors:\n result = dict(errors)\n status = 400\n return JsonResponse(data=result, status=status)'
In template I have next results (with tag linebreaksbr):
class UpdateAccountInfo(LoginRequiredMixin, View):
"""
View for update information about account of user
"""
def post(self, request, *args, **kwargs):
if request.is_ajax():
result = dict()
status = 200
try:
if request.FILES:
coordinates_x1 = int(request.POST.get('coordinates[x1]'))
coordinates_y1 = int(request.POST.get('coordinates[y1]'))
coordinates_x2 = int(request.POST.get('coordinates[x2]'))
coordinates_y2 = int(request.POST.get('coordinates[y2]'))
field = 'account_user_info-picture'
value = request.FILES[field]
new = {field: value}
"""
View for update information about account of user
"""
def post(self, request, *args, **kwargs):
if request.is_ajax():
result = dict()
status = 200
try:
if request.FILES:
coordinates_x1 = int(request.POST.get('coordinates[x1]'))
coordinates_y1 = int(request.POST.get('coordinates[y1]'))
coordinates_x2 = int(request.POST.get('coordinates[x2]'))
coordinates_y2 = int(request.POST.get('coordinates[y2]'))
field = 'account_user_info-picture'
value = request.FILES[field]
new = {field: value}
but I need right displaying as in terminal with function print():
In [61]: print(a.code)
class UpdateAccountInfo(LoginRequiredMixin, View):
"""
View for update information about account of user
"""
def post(self, request, *args, **kwargs):
if request.is_ajax():
result = dict()
status = 200
try:
if request.FILES:
coordinates_x1 = int(request.POST.get('coordinates[x1]'))
coordinates_y1 = int(request.POST.get('coordinates[y1]'))
coordinates_x2 = int(request.POST.get('coordinates[x2]'))
coordinates_y2 = int(request.POST.get('coordinates[y2]'))
field = 'account_user_info-picture'
value = request.FILES[field]
new = {field: value}
account_info = AccountUserInfo.objects.get(account=self.request.user)
account_info.picture = value
account_info.full_clean()
account_info.save()
picture_file = Image.open(account_info.picture.path)
cropped_picture = picture_file.crop([coordinates_x1, coordinates_y1, coordinates_x2, coordinates_y2])
cropped_picture.save(account_info.picture.path)
result['new_image_url'] = account_info.picture.url
else:
field = self.request.POST['field']
value = self.request.POST['value']
if field == 'datetimepicker_for_birthday_account':
correct_field = 'birthday'
else:
correct_field = field.replace('account_user_info-', '')
new = {correct_field: value}
account_info = AccountUserInfo.objects.filter(account=self.request.user)
AccountUserInfo(**new).full_clean(exclude=['account'])
account_info.update(**new)
account_info = AccountUserInfo.objects.get(account=self.request.user)
result['new_value_progresbar_filling_account_info'] = account_info.filling_account_info()
except BaseException as errors:
result = dict(errors)
status = 400
return JsonResponse(data=result, status=status)
How I can achieve this?
Thanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/84be2d70-9408-4611-b702-2bfffcd43f67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment