flask-extensions

flask-admin not showing foreignkey columns

梦想与她 提交于 2019-12-05 02:38:39
class Parent(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(120)) def __repr_(self): return '<Parent %r>' % (self.name) admin.add_view(ModelView(Parent, db.session)) class Child(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(120)) parent = db.Column(db.Integer, db.ForeignKey(Parent)) admin.add_view(ModelView(Child, db.session)) Hello - The code above is an example of flask-admin page that I am trying to create. The goal is to have on Child's create page a text box for name and a drop down to select a parent. With the

how to use flask-cache and memcached?

拟墨画扇 提交于 2019-12-04 16:25:41
an example for flask-cache with type "simple" below but how can i use flask-cache with memcache ? I need ur help thank you :) from flask import Flask import random # import the flask extension from flask.ext.cache import Cache app = Flask(__name__) #import config setting app.config["CACHE_TYPE"]="simple" # register the cache instance and binds it on to your app app.cache = Cache(app) @app.route("/") @app.cache.cached(timeout=50,key_prefix="hello") # cache this view for 30 seconds def cached_view(): a=random.randint(0,100) return str(a) if __name__ == "__main__": app.run(port=5000, debug=True,

How to manually install Flask extensions?

和自甴很熟 提交于 2019-12-04 10:58:07
I have a Flask project which I've put the flask module (version 0.9) directly beside my app.py file. I've done this so that I can bundle everything into a version control repository that won't require anyone else using it to install additional Python modules. I want to use flask-login so I've tried to manually install it by downloading the latest version and putting the flask_login.py file in my "local" flask/ext/ directory. However, while I can import flask and import flask.ext , I am unable to import flask.ext.login with Python throwing ImportError: No module named flask.ext.login . import

How to use Flask-Security register view?

倖福魔咒の 提交于 2019-12-03 10:18:35
Has anyone used Flask-Security extension for authentication? How do I get register view to work? http://packages.python.org/Flask-Security/customizing.html I am referring to link above. @app.route('/register', methods=['GET']) def register(): return render_template('security/register_user.html') I don't want to extend the default class, I just want to wrap the default registration view in my site layout so I did this. {% extends "layout.html" %} {% block title %}upload{% endblock %} {% block body %} {% from "security/_macros.html" import render_field_with_errors, render_field %} {% include

python group/user management packages

拟墨画扇 提交于 2019-12-02 19:46:33
I was looking for python user/group management package.(Creation of user group and adding/removing members to that group) I found flask_dashed. https://github.com/jeanphix/Flask-Dashed/ It more or less what I was looking for. But It supports only one user to add/remove groups. Does any one know what are the other such similar packages available in python-flask world? I literally just did this myself yesterday. I did it with a combination of Flask-Login Flask-Principal Flask-SQLAlchemy Basically the way it works is like this. Flask-Login is used for user authentication. On successful login, a

How to stop flask application without using ctrl-c

孤街浪徒 提交于 2019-11-27 11:31:48
I want to implement a command which can stop flask application by using flask-script. I have searched the solution for a while. Because the framework doesn't provide "app.stop()" API, I am curious about how to code this. I am working on Ubuntu 12.10 and Python 2.7.3. Zorayr If you are just running the server on your desktop, you can expose an endpoint to kill the server (read more at Shutdown The Simple Server ): from flask import request def shutdown_server(): func = request.environ.get('werkzeug.server.shutdown') if func is None: raise RuntimeError('Not running with the Werkzeug Server')

Flask-Login - How to get Session ID

岁酱吖の 提交于 2019-11-27 02:18:53
问题 Am doing a project with Flask, Gevent and web socket using flask development server environment. I used flask_login . Here how can get i get the Unique Session ID for each connection? I want to store the SessionID in the Database and delete it once client disconnects. How to get total active connections from flask_login import * login_manager = LoginManager() login_manager.setup_app(app) @app.route("/", methods=["GET", "POST"]) def login(): login_user([username], remember): @app.route("

ImportError: No module named flaskext.sqlalchemy

我与影子孤独终老i 提交于 2019-11-26 21:10:54
I am trying to use the Sign in with SteamID snippet from the Flask site. However, I get ImportError: No module named flaskext.sqlalchemy when I try to run it, and PyCharm says Uresolved reference "flaskext" and Uresolved reference "OpenID" . I re-installed Flask-OpenID and Flask-SQLAlchemy to make sure they were there. Why am I getting this error and how do I fix it? That snippet is really old. flaskext is no more (or at least very deprecated). Refer to packages directly rather than through flaskext or flask.ext . from flask_sqlalchemy import SQLAlchemy Flask-SQLAlchemy (and most other

How to stop flask application without using ctrl-c

末鹿安然 提交于 2019-11-26 10:27:25
问题 I want to implement a command which can stop flask application by using flask-script. I have searched the solution for a while. Because the framework doesn\'t provide \"app.stop()\" API, I am curious about how to code this. I am working on Ubuntu 12.10 and Python 2.7.3. 回答1: If you are just running the server on your desktop, you can expose an endpoint to kill the server (read more at Shutdown The Simple Server): from flask import request def shutdown_server(): func = request.environ.get(