flask-extensions

How to track the current user in flask-login?

心已入冬 提交于 2019-12-18 12:15:02
问题 I m trying to use the current user in my view from flask-login. So i tried to g object I m assigning flask.ext.login.current_user to g object @pot.before_request def load_users(): g.user = current_user.username It works if the user is correct. But when i do sign-up or login as with wrong credentials I get this error AttributeError: 'AnonymousUserMixin' object has no attribute 'username' Please enlight me where am i wrong... 回答1: Thanks for your answer @Joe and @pjnola, as you all suggested i

ImportError: No module named flaskext.sqlalchemy

寵の児 提交于 2019-12-17 05:15:15
问题 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? 回答1: That snippet is really old. flaskext is no more (or at least very deprecated). Refer to packages directly rather than

ImportError: No module named flaskext.sqlalchemy

佐手、 提交于 2019-12-17 05:15:12
问题 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? 回答1: That snippet is really old. flaskext is no more (or at least very deprecated). Refer to packages directly rather than

Jinja2 extension outputs escaped html instead of html tag

送分小仙女□ 提交于 2019-12-13 02:59:40
问题 I'm trying to write a simple jinja2 extension that'll render a <meta> tag in the page with some property and content attr. It looks something like this: from jinja2 import nodes from jinja2.ext import Extension class MetaExtension(Extension): """ returns a meta tag of key, value >> env = jinja2.Environment(extensions=[MetaExtension]) >> env.from_string('{% meta "key", "value" %}').render() u'<meta property="keyword" content="value" />' """ # we'll use it in the template with tags = set(['meta

Unable to create models on Flask-admin

梦想的初衷 提交于 2019-12-12 07:32:09
问题 I'm creating a simple blog on Flask and I'm trying to implement Flask-Admin to manage my posts. If I go to the admin area I can see a list of all my post from the DB but when I try to create a new one I got the next error: Failed to create model. __init__() takes exactly 4 arguments (1 given) This is my post model: class Post(db.Model): __tablename__ = 'news' nid = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(100)) content = db.Column(db.Text) created_at = db.Column

url_for Builderror in flask extension with pluggable views

痴心易碎 提交于 2019-12-11 10:42:20
问题 I am building a simple extension for flask and have a problem with the url_for function not being able to build the urls within the extension. Can somebody help me figure out what I am missing here? I simplified the code to demonstrate the issue (all of the url_for calls raise a werkzeug BuildError exception): import flask import flask.views import logging logging.basicConfig(level=logging.DEBUG) class MyFlaskExt(object): def __init__(self, app=None): if app is not None: self.init_app(app)

flask-login session gets destroyed on every apache restart

半世苍凉 提交于 2019-12-07 20:56:12
问题 I am using flask-login https://github.com/maxcountryman/flask-login and the field remember in login_user does not seem to work. The session gets destroyed after every restart of the apache ..ideally the remember field should take care of this.. even the session values gets destroyed. this is really frustrating... anyone knowing the solution please ping .. thanks i am using login_user as login_user(user, remember=True) 回答1: If anyone is suffering with this problem, you have to write the

flask-admin not showing foreignkey columns

拈花ヽ惹草 提交于 2019-12-06 22:08:22
问题 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

how to use flask-cache and memcached?

心不动则不痛 提交于 2019-12-06 09:45:04
问题 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

flask-login session gets destroyed on every apache restart

ε祈祈猫儿з 提交于 2019-12-06 09:38:25
I am using flask-login https://github.com/maxcountryman/flask-login and the field remember in login_user does not seem to work. The session gets destroyed after every restart of the apache ..ideally the remember field should take care of this.. even the session values gets destroyed. this is really frustrating... anyone knowing the solution please ping .. thanks i am using login_user as login_user(user, remember=True) If anyone is suffering with this problem, you have to write the function user_loader properly. @login_manager.user_loader def load_user(id): return "get the user properly and