def should_be_able_to_work_without_providing_server_port_user_and_password_for_database_connection(self):
        from flaskext.mongoalchemy import MongoAlchemy

        app = Flask("newest_test")
        app.config["MONGOALCHEMY_DATABASE"] = "my_database"
        db = MongoAlchemy(app)
        assert_equals(app.config["MONGOALCHEMY_SERVER"], "localhost")
        assert_equals(app.config["MONGOALCHEMY_PORT"], "27017")
        assert_equals(app.config["MONGOALCHEMY_USER"], None)
        assert_equals(app.config["MONGOALCHEMY_PASSWORD"], None)
Beispiel #2
0
from flask import Flask, render_template, request
from flaskext.mongoalchemy import MongoAlchemy

app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "library"
db = MongoAlchemy(app)


class Author(db.Document):
    username = db.StringField()


# class Book(db.Document):
#    title = db.StringField()
#    author = db.DocumentField(Author)
#    year = db.IntField()


@app.route("/", methods=["POST", "GET"])
def index():
    if request.method == "POST":
        usernameform = request.form["username"]
        data = Author(username=usernameform)
        data.save()
    data = Author.query
    return render_template("index.html", data=data)


if __name__ == "__main__":
    app.debug = True
    app.run()