V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Kilerd  ›  全部回复第 235 页 / 共 286 页
回复总数  5719
1 ... 231  232  233  234  235  236  237  238  239  240 ... 286  
2016-02-22 11:49:23 +08:00
回复了 icedx 创建的主题 天黑以后 20160222 午夜俱乐部
@Elethom 辣么可爱,肯定是蓝孩子。
2016-02-22 00:09:31 +08:00
回复了 icedx 创建的主题 天黑以后 20160222 午夜俱乐部
说你是不是写了脚本。。。哼。
2016-02-20 16:43:14 +08:00
回复了 acrisliu 创建的主题 分享发现 分享一个 Minecraft 服务器,大家可以一起来玩。
连领地保护都没有么? 又没有玩家审核功能,被人进来 TNT 一下,可能几个月的心思就没了。
2016-02-20 11:05:51 +08:00
回复了 nonozone 创建的主题 问与答 100 块左右能买到啥有意思或者有用的东西?
@mystryl 主要是不知道买什么皮好。各式各样,难挑选。
2016-02-20 11:05:13 +08:00
回复了 VmuTargh 创建的主题 问与答 以前看着别人迷茫,现在轮到我了——要不要转理科?
@VmuTargh 微积分,然后推导出公式。日常生活的简易模型。
@wizardforcel 我高中会写 PHP 了。
2016-02-20 01:12:02 +08:00
回复了 icedx 创建的主题 天黑以后 20160220 午夜俱乐部
2016-02-20 01:11:14 +08:00
回复了 VmuTargh 创建的主题 问与答 以前看着别人迷茫,现在轮到我了——要不要转理科?
@VmuTargh 物理在理科里面算简单的了
2016-02-20 00:42:57 +08:00
回复了 nonozone 创建的主题 问与答 100 块左右能买到啥有意思或者有用的东西?
@mystryl 求各种工具和皮的链接。
2016-02-19 14:13:08 +08:00
回复了 icedx 创建的主题 天黑以后 20160219 午夜俱乐部
@icedx 居然找到了出处
2016-02-19 00:59:12 +08:00
回复了 icedx 创建的主题 天黑以后 20160219 午夜俱乐部
2016-02-19 00:51:42 +08:00
回复了 icedx 创建的主题 天黑以后 20160219 午夜俱乐部
又是玩了一天游戏。想了下自己的那几个项目,再想想开学后比赛的几个项目(虽然这几个只写后台,只负责 API ),就鉴定了自己玩下去的决心。
把你的 用户模型 和 关于 flask_login 的代码贴出来。
2016-02-18 23:37:53 +08:00
回复了 mikicomo 创建的主题 Go 编程语言 Go 1.6 发布,默认使用 Cgo ,支持 HTTP/2
@mikicomo Misaka Mikoto 御坂美琴,传说中的炮姐
@fatea 未登录的可以自己写一个装饰器啊。

def require_not_login(func):
@wraps(func)
----def decorated_view(*args, **kwargs):
--------if not current_user.is_authenticated():
------------return func(*args, **kwargs)
--------else:
------------flash(_"you must log out before doing this.", "error")
------------return redirect(url_for("..."))
2016-02-18 23:30:15 +08:00
回复了 aaronly 创建的主题 PHP 分享寒假无聊撸出来的 Material Design 风格的博客系统
2016-02-18 23:29:28 +08:00
回复了 mikicomo 创建的主题 Go 编程语言 Go 1.6 发布,默认使用 Cgo ,支持 HTTP/2
2016-02-18 23:26:46 +08:00
回复了 mikicomo 创建的主题 Go 编程语言 Go 1.6 发布,默认使用 Cgo ,支持 HTTP/2
上面的代码看不清楚,请移至 markdown 编辑器中查看,懒得用 gist 了 http://ww4.sinaimg.cn/bmiddle/62e721e4gw1et02g5wksrj200k00k3y9.jpg
@fatea flask-login 不是自带登陆检测装饰器吗?

from flask_login import login_required


以下是他的代码:
''' python
def login_required(func):
'''
If you decorate a view with this, it will ensure that the current user is
logged in and authenticated before calling the actual view. (If they are
not, it calls the :attr:`LoginManager.unauthorized` callback.) For
example::

@app.route('/post')
@login_required
def post():
pass

If there are only certain times you need to require that your user is
logged in, you can do so with::

if not current_user.is_authenticated:
return current_app.login_manager.unauthorized()

...which is essentially the code that this function adds to your views.

It can be convenient to globally turn off authentication when unit testing.
To enable this, if the application configuration variable `LOGIN_DISABLED`
is set to `True`, this decorator will be ignored.

:param func: The view function to decorate.
:type func: function
'''
@wraps(func)
def decorated_view(*args, **kwargs):
if current_app.login_manager._login_disabled:
return func(*args, **kwargs)
elif not current_user.is_authenticated:
return current_app.login_manager.unauthorized()
return func(*args, **kwargs)
return decorated_view
'''


BTW , is_authenticated 只是你的用户 ORM 模型里面的一个函数,用来验证是否用户通过验证罢了,并不是 boolean

` current_user = LocalProxy(lambda: _get_user()) `

根据你的设置,只想到你的用户 ORM 模型

所以 ` current_user.is_authenticated ` 就应该是自己设置的。 当然如果你不需要用到这个字段,设置成 boolean 或者 True 也是可以得。

未登录的使用 可以用

`if not current_user.is_authenticated(): pass `
1. current_user 默认都不是 None
2. is_authenticated => is_authenticated() 这是一个函数。

至于你说的 问题, 草草看一眼没看出来 http://ww4.sinaimg.cn/bmiddle/62e721e4gw1et02g5wksrj200k00k3y9.jpg
1 ... 231  232  233  234  235  236  237  238  239  240 ... 286  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2412 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 55ms · UTC 03:55 · PVG 11:55 · LAX 20:55 · JFK 23:55
Developed with CodeLauncher
♥ Do have faith in what you're doing.