how to connect html form to CRUD api python code example
Example 1: sqlite3 with flask web application CRUD pdf
from flask import abort, Flask, render_template
def create_app(config_name):
@app.route('/500')
def error():
abort(500)
return app
Example 2: sqlite3 with flask web application CRUD pdf
import unittest
from flask_testing import TestCase
from app import create_app, db
from app.models import Employee
class TestBase(TestCase):
def create_app(self):
config_name = 'testing'
app = create_app(config_name)
app.config.update(
SQLALCHEMY_DATABASE_URI='mysql://dt_admin:dt2016@localhost/dreamteam_test'
)
return app
def setUp(self):
"""
Will be called before every test
"""
db.create_all()
admin = Employee(username="admin", password="admin2016", is_admin=True)
employee = Employee(username="test_user", password="test2016")
db.session.add(admin)
db.session.add(employee)
db.session.commit()
def tearDown(self):
"""
Will be called after every test
"""
db.session.remove()
db.drop_all()
if __name__ == '__main__':
unittest.main()