July 2018
Intermediate to advanced
324 pages
8h 14m
English
We created the instance of a blueprint for todo, and we will use this instance to create the routes in views. The following is the code snippet for views.
File—todo/views.py:
import jsonfrom flask import render_template, redirect, url_for, jsonify, requestfrom flask_login import login_required, current_userfrom app.todo import todofrom app.todo.forms import TodoFormfrom app.todo.models import Todo@todo.route('/', methods=['GET', 'POST'])@login_requireddef list(): context = dict() form = TodoForm() if form.validate_on_submit(): Todo(form.title.data, created_by=current_user.email).save() return redirect(url_for('todo.list')) context['form'] = form context['todos'] = current_user.todos context['items_left'] = len([todo for todo in current_user.todos ...Read now
Unlock full access