-2

I keep having an issue with the module datetime at this section of the code whenever i run it, it should add the time to the alarm manager from the datetime-local input from the html part. But whenever the text and date are added an error of datetime.datetime is not an attribute of datetime.

from datetime import datetime

alarm_datetime = datetime.datetime(*alarm_tmp)
davidism
  • 121,510
  • 29
  • 395
  • 339
Karna
  • 138
  • 7
  • 2
    Perhaps `alarm_datetime = datetime.datetime(*alarm_tmp)` should just be `alarm_datetime = datetime(*alarm_tmp)`? You've already imported `datetime` from the `datetime` package already, so you don't need to do `datetime.datetime(...)`. – aphrid Nov 06 '19 at 19:08

3 Answers3

2

If you do

from datetime import datetime

You don't need to

alarm_datetime = datetime.datetime(*alarm_tmp)

Instead, just do

alarm_datetime = datetime(*alarm_tmp)
Roni Antonio
  • 1,334
  • 1
  • 6
  • 11
1

You should only use datetime and not datetime.datetime in your code. To use your code:

@app.route('/',methods=['POST','GET'])      #adding two methods posting and getting
def index():
    if request.method == 'POST':    #submitting form
        task_content = request.form['content'] #create new task from user input
        alarm_content = request.form['alarm']
        alarm_tmp = alarm_content.replace('T', '-').replace(':', '-').split('-')
        alarm_tmp = [int(v) for v in alarm_tmp]
        alarm_datetime = datetime(*alarm_tmp)
        task = Table(content=task_content,alarm=alarm_content)
Philippe Oger
  • 1,021
  • 9
  • 21
0

It looks like your issue stems from the import and usage.

from datetime import datetime

Later on in your index() method you have

alarm_datetime = datetime.datetime(*alarm_tmp)

Here is an SO question that has an additional info on the error: type object 'datetime.datetime' has no attribute 'datetime'

teichopsia
  • 26
  • 2
  • 3