Advertisement
agel122

weight_converter(django.views)

Jul 7th, 2021
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. def weight_converter(request):
  2.     if request.method == 'POST':
  3.         form = Adder(request.POST)
  4.         if form.is_valid():
  5.             try:
  6.                 value_in_g = int(form.cleaned_data['added_data'])
  7.                 result_kg = value_in_g/1000
  8.                 return render(request, 'weight_converter.html',
  9.                               {'result': result_kg, 'initial_value': value_in_g,})
  10.             except ValueError as e:
  11.                 e.message = 'Enter the number, not the string'
  12.                 return render(request, 'weight_converter.html', {'message': e.message})
  13.     else:
  14.         form = Adder()
  15.     return render(request, 'weight_converter.html', {'form': form})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement