now with the ability to post new tasks
This commit is contained in:
14
app.py
14
app.py
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from datetime import datetime, time, date
|
||||
import time
|
||||
from datetime import datetime, date
|
||||
from flask import Flask, render_template, request, redirect, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
@@ -62,6 +63,17 @@ def tasks():
|
||||
tasks = Task.query.all()
|
||||
return render_template('tasks.html', str=str, tasks=tasks, datetime=datetime, date=date)
|
||||
|
||||
@app.route('/task/new', methods=('GET', 'POST'))
|
||||
def newTask():
|
||||
if request.method == 'POST':
|
||||
task = Task(title=request.form['title'],
|
||||
description=request.form['description'],
|
||||
created_timestamp=int(time.time()))
|
||||
db.session.add(task)
|
||||
db.session.commit()
|
||||
return redirect(f'/task/{task.id}')
|
||||
return render_template('newtask.html')
|
||||
|
||||
@app.route('/task/<int:task_id>/')
|
||||
def task(task_id):
|
||||
task = Task.query.get_or_404(task_id)
|
||||
|
Reference in New Issue
Block a user