我有以下查询:
profiles = session.query(profile.name).filter(and_(profile.email == email, profile.password == password_hash))
Run Code Online (Sandbox Code Playgroud)
如何检查是否有一行,如何返回第一行(如果匹配则应该只有一行)?
我目前正在开发我的第一个真正的python烧瓶项目,并且即将设置构建服务器以部署每次签入时构建的"最新构建".
我已经设置了一个启动脚本,我使用uwsgi启动应用程序,这部分工作正常.我最近也开始使用virtualenv,通过这样做,安装的软件包被添加到我的项目下projectname\flask\Lib\site-packages.
我nginx用作Web服务器,配置如下所示:
location / { try_files $uri @graderbuild; }
location @graderbuild {
include uwsgi_params;
uwsgi_param UWSGI_CHDIR /usr/local/grader/build;
uwsgi_param UWSGI_PYHOME /usr/local/grader/build;
uwsgi_pass 127.0.0.1:3031;
}
Run Code Online (Sandbox Code Playgroud)
我开始uwsgi使用这个:
exec /usr/local/bin/uwsgi --master --socket 127.0.0.1:3031
--wsgi-file restserver.py --callable app --processes 4 --die-on-term
--threads 2 >> /var/log/grader-build.log 2>&1
Run Code Online (Sandbox Code Playgroud)
现在到我知道我做得对的地方......目前我正在将整个文件夹部署到构建服务器.我不想安装全局python模块只是为了让我的构建工作.对还是错?
我目前得到的错误是:
ImportError: No module named flask_wtf
Run Code Online (Sandbox Code Playgroud)
如果我是对的,如何配置设置以使用virtualenv站点包?我首选的位置是在startup脚本中,而不是在nginx配置中.
我将这些标头由服务器发送到客户端:
Cache-Control:private
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html
Date:Sun, 27 Nov 2011 11:10:38 GMT
ETag:"12341234"
Set-Cookie:connect.sid=e1u...7o; path=/; expires=Sun, 27 Nov 2011 11:40:38 GMT; httpOnly
Transfer-Encoding:chunked
last-modified:Sat, 26 Nov 2011 21:42:45 GMT
Run Code Online (Sandbox Code Playgroud)
我希望客户端验证文件在服务器上没有更改,如果否则为"304",则发送"200".
Firefox发送:
if-modified-since: Sat, 26 Nov 2011 21:42:45 GMT
if-none-match: "12341234"
Run Code Online (Sandbox Code Playgroud)
为什么Chrome不会在刷新页面时发送相同内容?我正在追踪.Net运行的行为:
context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate)
Run Code Online (Sandbox Code Playgroud) 我正在实现一个网格面板,其中最后四列可编辑为大多数行.问题是我希望能够禁用编辑,假设第一个如果record.get('status')= 4,那么最终确定并且只有两列可以编辑.
有没有办法禁用显示这些行的编辑?我可以使用CellEditing来做,但想继续使用RowEditing插件.
此致,克里斯蒂安
我想设置一个具有特定权限的特定文件夹,以继承其父文件夹的所有权限.我知道我应该用icacls.
我的文件夹看起来像这样:
- mp
- build (set this one to inherit from mp)
Run Code Online (Sandbox Code Playgroud) 我正在使用virtualenv来建立一个新项目.我在脚本文件夹中使用virtualenv pip安装了很多东西,如下所示:
flask\scripts\pip install Flask-WTF
Run Code Online (Sandbox Code Playgroud)
我没有在全局python文件夹中安装其他软件包.我的代码看起来像这样:
# Importing TextField and BooleanField is not working...
from flask.ext.wtf import Form, TextField, BooleanField
from flask.ext.wtf import Required
class LoginForm(Form):
openid = TextField('openid', validators=[Required()])
remember_me = BooleanField('remember_me', default=False)
Run Code Online (Sandbox Code Playgroud)
和其他软件包一样,sqlalchemy也只安装在虚拟环境中.
我得到的错误是:
(flask) D:\Development\grading>flask\Scripts\python.exe restserver.py Traceback (most recent call last):
File "restserver.py", line 1, in <module> from app import app
File "D:\Development\grading\app\__init__.py", line 12, in <module> from forms import LoginForm
File "D:\Development\grading\app\forms.py", line 1, in <module> from flask.ext.wtf import Form, TextField, BooleanField
File "D:\Development\grading\flask\lib\site-packages\flask\exthook.py", line 87, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用在nginx中代理的连接运行nodejs的nginx和nodejs.我遇到的问题是我目前不在root(/)下运行nodejs但在/ data下运行nginx应该正常处理静态请求.nodejs不应该知道它在/ data下,但它似乎是必需的.
换一种说法.我希望nodejs"思考"它在/运行.那可能吗?
nginx配置:
upstream app_node {
server 127.0.0.1:3000;
}
server {
...
location /data {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_node/data;
proxy_redirect off;
}
}
Run Code Online (Sandbox Code Playgroud)
nodejs代码:
exports.routes = function(app) {
// I don't want "data" here. My nodejs app should be able to run under
// any folder
app.get('/data', function(req, res, params) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.end('app.get /data');
});
// I don't want "data" here either
app.get('/data/test', function(req, …Run Code Online (Sandbox Code Playgroud) 我有一个与sqlalchemy和postgresql相关的问题.
class Profile(Base):
...
roles = relationship('Role', secondary=role_profiles,
backref='profiles', lazy='dynamic')
Run Code Online (Sandbox Code Playgroud)
运行时(current_user是Profile类的实例):
roles = current_user.roles.filter().all()
Run Code Online (Sandbox Code Playgroud)
使用sqlalchemy我得到idle in transaction了所有选择,以便在postgresql中读取配置文件.
编辑:
从回显查询中我看到每个选择都以:
BEGIN (implicit)
Run Code Online (Sandbox Code Playgroud)
另一个编辑:
添加后
pool_size=20, max_overflow=0
Run Code Online (Sandbox Code Playgroud)
在create_engine它好像idle in transaction-statements被回滚时空闲的数量越来越变大.有任何想法,这将是一个解决问题的坏方法吗?
我如何管理这个以及如何摆脱BEGIN选择呢?
我正在为我正在开发的应用编写REST API.该应用程序是用python写的.我有以下内容:
try:
_profile = profile(
name=request.json['name'],
password=profile.get_salted_password('blablabla'),
email=request.json['email'],
created_by=1,
last_updated_by=1
)
except AssertionError:
abort(400)
session = DatabaseEngine.getSession()
session.add(_profile)
try:
session.commit()
except IntegrityError:
abort(400)
Run Code Online (Sandbox Code Playgroud)
错误处理程序如下所示:
@app.errorhandler(400)
def not_found(error):
return make_response(standard_response(None, 400, 'Bad request'), 400)
Run Code Online (Sandbox Code Playgroud)
我正在使用错误400来表示sqlalchemy模型验证器的问题和写入数据库时的唯一约束,并且在这两种情况下都会向客户端发送以下错误:
{
"data": null,
"error": {
"msg": "Bad request",
"no": 400
},
"success": false
}
Run Code Online (Sandbox Code Playgroud)
有没有办法仍然使用abort(400),但也以某种方式设置错误,以便错误处理程序可以负责在结果中添加错误对象的附加信息?
我希望它更符合:
{
"data": null,
"error": {
"msg": "(IntegrityError) duplicate key value violates unique constraint profile_email_key",
"no": 400
},
"success": false
}
Run Code Online (Sandbox Code Playgroud) 我的CMakeFiles.txt看起来像这样:
cmake_minimum_required ( VERSION 2.6 )
# Set warnings on and enable debugging
SET( CMAKE_C_FLAGS "-Wall -q" )
include(FindBoost)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
if( Boost_FOUND )
message( STATUS "Boost found!" )
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
# Needed for asio
if(WIN32)
target_link_libraries(foo wsock32 ws2_32)
endif()
target_link_libraries(foo ${Boost_LIBRARIES})
endif()
Run Code Online (Sandbox Code Playgroud)
我为Visual Studio 2013 64位渲染项目:
cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:\Development\Tools\boost_1_57_0\stage\x64\lib ..\KServer
Run Code Online (Sandbox Code Playgroud)
输出是:
-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX …Run Code Online (Sandbox Code Playgroud) python ×5
flask ×4
node.js ×2
sqlalchemy ×2
boost ×1
c++ ×1
cmake ×1
extjs4 ×1
grid ×1
http ×1
http-headers ×1
icacls ×1
import ×1
nginx ×1
session ×1
transactions ×1
uwsgi ×1
virtualenv ×1
windows ×1
wtforms ×1