stgleb | 75c7041 | 2015-02-17 02:52:00 +0200 | [diff] [blame] | 1 | from flask import Flask, render_template, request, url_for, request, redirect |
| 2 | from flask.ext.sqlalchemy import SQLAlchemy |
| 3 | import sqlite3 |
| 4 | import os |
| 5 | |
| 6 | app = Flask(__name__) |
| 7 | sqlite3.connect(os.path.abspath("test.db")) |
| 8 | app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///test.db" |
| 9 | db = SQLAlchemy(app) |
| 10 | |
| 11 | |
| 12 | class User(db.Model): |
| 13 | id = db.Column(db.Integer, primary_key=True) |
| 14 | username = db.Column(db.String(80), unique=True) |
| 15 | email = db.Column(db.String(120), unique=True) |
| 16 | |
| 17 | def __init__(self, username, email): |
| 18 | self.username = username |
| 19 | self.email = email |
| 20 | def __repr__(self): |
| 21 | return "<User %r>" % self.username |
| 22 | |
| 23 | |
| 24 | db.create_all() |
| 25 | x = User("tes2t", "test2@gmail.com") |
| 26 | db.session.add(x) |
| 27 | db.session.commit() |
| 28 | |
| 29 | |