F
F
filmincer2016-05-20 17:29:57
Django
filmincer, 2016-05-20 17:29:57

Django throws an error: unsupported operand type(s) for -: 'str' and 'str'?

Hello.
I'm trying to print the data in the console correctly, namely the range of dates (in the form of strings).
On the last line (where print) Django gives an error: unsupported operand type(s) for -: 'str' and 'str'
This line worked well as an object method in the Model, but in the view it was a problem. I tried to remove str(), output not in a sheet .. it's still the same.

class CartView(SingleObjectMixin, View):
.....
          def get(self, request, *args, **kwargs):
      start = request.GET.get("start")
      end = request.GET.get("end")
      print ([str(end - datetime.timedelta(i)) for i in range((end - start).days+1)])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-05-20
@filmincer

0. Пока не стал шаманом не используй данные из request.GET request.POST в чистом виде
Для приема данных есть формы. Бери данные только после валидации и очистки
1. Ты пытаешься вычесть из строки дату
Для тебя ето легко, но питон к такой фигне не привык

I
iegor, 2016-05-20
@iegor

end, start строки...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question