Я пытаюсь получить пользовательский ввод (DateField) из моего приложения django, этот код дает мне вышеуказанную ошибку
Код ошибки:
def home(request):
today = datetime.date.today()
# If this is a POST request then process the Form data
if request.method == 'GET':
form = DeadlineForm(request.GET)
# instance = form.save()
currentdate = datetime.date.today()
print(currentdate)
userinput = formd.data
birthday = datetime.datetime.strptime(userinput, '%m/%d/%Y').date()
# print(birthday)
days = birthday - currentdate
daysLeft = 'Days to your birthday is ' ,+ days
return HttpResponse(daysLeft)
context = {
'form': form,
'today':today
}
return render(request, 'calculator/home.html', context)
Но когда я использую строковый формат датывсе работает нормально, но я хочу, чтобы пользователи могли вставлять свою собственную дату.
код без ошибок:
def home(request):
today = datetime.date.today()
# If this is a POST request then process the Form data
if request.method == 'GET':
form = DeadlineForm(request.GET)
# instance = form.save()
currentdate = datetime.date.today()
print(currentdate)
# userinput = formd.data
birthday = datetime.datetime.strptime('03/15/2019', '%m/%d/%Y').date()
# print(birthday)
days = birthday - currentdate
daysLeft = 'Days to your birthday is ' ,+ days
return HttpResponse(daysLeft)
context = {
'form': form,
'today':today
}
return render(request, 'calculator/home.html', context)
Может кто-нибудь показать мне, как получить строковый ввод от пользователя.