我的查询是:
result = connection.execute(
"select id_number from Table where string like '_stringStart%' limit 1;")
Run Code Online (Sandbox Code Playgroud)
给出错误:
query = query % escaped_args
TypeError: not enough arguments for format string
Run Code Online (Sandbox Code Playgroud)
一个快速的谷歌说使用%%而不是%,但这也不起作用.如何转义%或是否有另一种方法来查询以随机字母开头然后是某个序列的字符串?
状态字段显示3个选项,但始终在submisison上显示"Not a valid choice",无论选择哪个.
from website import app, db
from flask.ext import admin
from flask.ext.admin.contrib import sqlamodel
from wtforms.fields import SelectField
class Users(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(160), unique=True)
status = db.Column(db.Integer)
def __repr__(self):
return self.name
class UsersAdmin(sqlamodel.ModelView):
form_overrides = dict(status=SelectField)
form_args = dict(
status=dict(
choices=[(0, 'Regular'), (1, 'Guest'), (2, 'Banned')],
))
admin = admin.Admin(app, 'Admin')
admin.add_view(UsersAdmin(Users, db.session))
Run Code Online (Sandbox Code Playgroud) 好的,在python中运行:
from mako.lookup import TemplateLookup
from mako.template import Template
mylookup = TemplateLookup(directories=['/home/user/webapps/app/www/templates/'])
mytemplate = Template(filename='/home/user/webapps/app/www/templates/content.html.mako', lookup=mylookup)
print (mytemplate.render(title="Title", content={'hi'}))
Run Code Online (Sandbox Code Playgroud)
当这是content.html.mako的开头
## content.html.mako
<%inherit file="frame.html.mako"/>
Run Code Online (Sandbox Code Playgroud)
给我这个:
mako.exceptions.TemplateLookupException: Cant locate template for uri '/home/user/webapps/app/www/templates/frame.html.mako'
Run Code Online (Sandbox Code Playgroud)
但frame.html.mako它和这里的目录是一样的content.html.mako,这里发生了什么?
我刚刚在Red Hat linux服务器上安装了Python2.6,该服务器随python2.4 preinstaleld提供.当我键入python时,启动python2.4,输入python2.6正确启动python 2.6.将2.6设为默认值的正确方法是什么?这个结果怎么可能:
$ python -V && which python && pwd && ./python -V
Python 2.4.3
/usr/local/bin/python
/usr/local/bin
Python 2.6.6
Run Code Online (Sandbox Code Playgroud) 谁能解释一下这里发生了什么?即使内置cmd.exe命令也无法正常工作:
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call('dir')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python34\lib\subprocess.py", line 535, in call
with Popen(*popenargs, **kwargs) as p:
File "D:\Python34\lib\subprocess.py", line 848, in __init__
restore_signals, start_new_session)
File "D:\Python34\lib\subprocess.py", line 1104, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
>>>
Run Code Online (Sandbox Code Playgroud) python ×5
linux ×2
sqlalchemy ×2
flask ×1
mako ×1
mysql ×1
subprocess ×1
windows ×1
wtforms ×1