草庐IT

USER_INFO

全部标签

python - Django 模型中的 request.user

我正在使用Django模型为表单创建字段。我希望自动检测并填写用户的用户名,这样我就可以将其隐藏在我的表单中(而不是让他们从拥有每个人用户名的长列表中选择他们的用户名)。为此,我正在使用:current_user=request.user然后将默认设置为current_user。但是,我不断收到此错误:NameError:name'request'isnotdefined我假设您不能在Django模型中使用请求,但是有什么方法可以解决这个问题吗?这是我的models.py文件的相关部分:classStockTickerSymbol(models.Model):StockName=mod

python - 如何将 logging.info 和 logging.debug 输出到控制台?

我只能看到警告和错误,我怎样才能打印出信息和调试?澄清一下,我使用pythonapp.py启动tornado应用程序。我希望在运行应用程序后将信息和调试日志打印到控制台。classMainHandler(tornado.web.RequestHandler):defget(self):self.write('hellofunfuntestworldfromtornadosuper')logging.info('info')logging.warning('warning')logging.error('error')logging.debug('debug')application=t

python - Rpy2 错误 wac-a-mole : R_USER not defined

我在Windows732位和R版本3.1.0上运行Python(x,y)2.7。我一直在尝试安装Rpy2,但遇到了很多错误。我终于找到了这个网站,它为Windows预编译了python模块http://www.lfd.uci.edu/~gohlke/pythonlibs/,所以我下载了rpy2‑2.4.2.win32‑py2.7.exe。当我这样做并尝试时importrpy2.robjectsasrobjects我有一个错误说它找不到R_HOME,所以我更新了我的路径变量。这是固定的,但后来我收到一条错误消息,说它找不到R_USER。我再次根据SO响应更新了我的PYTHONPATH变量

python - 如何在基于类的 View 中使用 user_passes_test 装饰器?

我试图在允许用户查看特定用户设置页面之前检查某些条件。我正在尝试使用user_passes_test装饰器来实现这一点。该函数位于基于类的View中,如下所示。我正在使用方法装饰器来装饰View中的get_initial函数。classUserSettingsView(LoginRequiredMixin,FormView):success_url='.'template_name='accts/usersettings.html'defget_form_class(self):ifself.request.user.profile.is_student:returnform1ifse

python - 处理来自 sys.exc_info() 的回溯对象时的适当注意和安全

我知道sys.exc_info文档说在处理回溯对象时要小心,但我仍然不确定某些情况下的安全性或不安全性。此外,文档说“警告:不要这样做!”,紧接着是“注意:实际上,没问题”,这让我更加困惑。在任何情况下,文档和“Whyisthereaneedtoexplicitlydeletethesys.exc_info()tracebackinPython?”(AlexMartelli的回答)似乎都暗示其唯一引用分配给它们的回溯值的局部变量会导致问题。这留给我几个问题:在这种情况下,“局部变量”到底是什么意思?我正在为术语而苦苦挣扎,但是:这是否意味着仅在函数中创建的变量,或者也由函数参数创建的变

python - Flask 登录和委托(delegate)人 - 即使我已登录,current_user 也是匿名的

我正在使用FlaskLogin和Principal进行身份和角色管理。我的需求直接从文档中描述出来。我的代码在这里:@identity_loaded.connect_via(app)defon_identity_loaded(sender,identity):#Settheidentityuserobjectidentity.user=current_user#AddtheUserNeedtotheidentityifhasattr(current_user,'get_id'):print'current_user'+str(current_user.get_id())identity

python - pip 无法安装任何东西,错误 : invalid command 'egg_info'

除了MacOSX自带的Python版本之外,我最近还从他们的网站下载了python。这是我开始在使用pip安装软件包时遇到问题。sudopipinstall-vvvpygoogle将输出如下:Thedirectory'/Users/robot/Library/Caches/pip/http'oritsparentdirectoryisnotownedbythecurrentuserandthecachehasbeendisabled.Pleasecheckthepermissionsandownerofthatdirectory.Ifexecutingpipwithsudo,youma

python - 如何将回溯对象( sys.exc_info()[2] ,与 sys.exc_traceback 相同)作为字符串获取?

我有一个捕获所有异常的函数,我希望能够在该函数中将回溯作为字符串获取。到目前为止这还行不通:defhandle_errors(error_type,error_message,error_traceback):"""catcherrors"""importtracebackerror={}error['type']=error_type.__name__error['message']=str(error_message)error['file']=os.path.split(error_traceback.tb_frame.f_code.co_filename)[1]error['l

python - 尝试推送通知时的 Cloud Pub/Sub Demo : 403 User not authorized to perform this action.

我正在学习GoogleCloudPub/Sub并遵循此官方文档:WritingandRespondingtoPub/SubMessages-Python当我将它部署到云端并尝试提交消息时,我收到以下错误:Aninternalerroroccurred:403Usernotauthorizedtoperformthisaction.(POSThttps://pubsub.googleapis.com/v1/projects/your-project-id/topics/your-topic:publish)Seelogsforfullstacktrace.我猜这是由于某些身份验证问题?任

python - tornadoweb 的配置失败 nginx 设置,未知指令 "user"

我在nginx版本1.0.0中遇到了这个错误nginx:[emerg]unknowndirective"user"in/etc/nginx/sites-enabled/tornado:1如果我删除用户www-data工作进程会出错nginx:[emerg]unknowndirective"worker_processes"in/etc/nginx/sites-enabled/tornado:1我在谷歌上搜索过,但还是一无所获请帮忙这是我在现场可用的Tornadouserwww-datawww-data;worker_processes1;error_log/var/log/nginx/