我收到的消息有很多错误:
"DatabaseError: current transaction is aborted, commands ignored until end of transaction block"
Run Code Online (Sandbox Code Playgroud)
之后从python-psycopg更改为python-psycopg2作为Django项目的数据库引擎.
代码保持不变,只是不知道这些错误来自哪里.
尝试将first_name,last_name保存到Django的auth_user模型时,我收到了奇怪的错误消息.
失败的例子
user = User.object.create_user(username, email, password)
user.first_name = u'Rytis'
user.last_name = u'Slatkevi?ius'
user.save()
>>> Incorrect string value: '\xC4\x8Dius' for column 'last_name' at row 104
user.first_name = u'???????'
user.last_name = u'????????'
user.save()
>>> Incorrect string value: '\xD0\x92\xD0\xB0\xD0\xBB...' for column 'first_name' at row 104
user.first_name = u'Krzysztof'
user.last_name = u'Szukie?oj?'
user.save()
>>> Incorrect string value: '\xC5\x82oj\xC4\x87' for column 'last_name' at row 104
Run Code Online (Sandbox Code Playgroud)
成功的例子
user.first_name = u'Marcin'
user.last_name = u'Król'
user.save()
>>> SUCCEED
Run Code Online (Sandbox Code Playgroud)
MySQL设置
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name …Run Code Online (Sandbox Code Playgroud) 我的本地机器在Ubuntu 8.10上运行Python 2.5和Nginx,Django是从最新的开发中继构建的.
对于我请求的每个URL,它会抛出:
TemplateDoesNotExist位于/ appname/path appname/template_name.html
Django尝试按以下顺序加载这些模板:*使用loader django.template.loaders.filesystem.function:*使用loader django.template.loaders.app_directories.function:
TEMPLATE_DIRS('/usr/lib/python2.5/site-packages/projectname/templates',)
在这种情况下,它是否在寻找/usr/lib/python2.5/site-packages/projectname/templates/appname/template_name.html?奇怪的是这个文件确实存在于磁盘上.为什么Django找不到它?
我在Ubuntu 9.04上使用Python 2.6在远程服务器上运行相同的应用程序,没有这样的问题.其他设置是相同的.
我的本地计算机上是否有任何配置错误,或者可能导致此类错误的内容我应该查看?
在我的settings.py中,我指定了:
SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__))
# Find templates in the same folder as settings.py.
TEMPLATE_DIRS = (
os.path.join(SETTINGS_PATH, 'templates'),
)
Run Code Online (Sandbox Code Playgroud)
它应该寻找以下文件:
以上所有文件都存在于磁盘上.
解决了
它在我尝试后现在有效:
chown -R www-data:www-data /usr/lib/python2.5/site-packages/projectname/*
Run Code Online (Sandbox Code Playgroud)
真奇怪.我不需要在远程服务器上执行此操作以使其工作.
是否可以使用以下组合打印shell命令的执行时间?
root@hostname:~# "command to execute" && echo "execution time"
Run Code Online (Sandbox Code Playgroud) 如何将RGBA颜色元组(例如96,96,96,202)转换为相应的RGB颜色元组?
编辑:
我想要的是在白色背景上获得与RGBA元组最相似的RGB值.
如何对Ctrl + C键事件进行多线程python程序响应?
编辑:代码是这样的:
import threading
current = 0
class MyThread(threading.Thread):
def __init__(self, total):
threading.Thread.__init__(self)
self.total = total
def stop(self):
self._Thread__stop()
def run(self):
global current
while current<self.total:
lock = threading.Lock()
lock.acquire()
current+=1
lock.release()
print current
if __name__=='__main__':
threads = []
thread_count = 10
total = 10000
for i in range(0, thread_count):
t = MyThread(total)
t.setDaemon(True)
threads.append(t)
for i in range(0, thread_count):
threads[i].start()
Run Code Online (Sandbox Code Playgroud)
我试图在所有线程上删除join()但它仍然无效.是因为每个线程的run()过程中的锁段?
编辑:上面的代码应该可以工作但是当当前变量在5,000-6,000范围内并且通过如下错误时它总是被中断
Exception in thread Thread-4 (most likely raised during interpreter shutdown):
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud) 如何在Django应用程序中获取所有表名?
我使用以下代码,但它没有得到ManyToManyField创建的表
from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app):
print model._meta.db_table
Run Code Online (Sandbox Code Playgroud) 如何在Python中将以下十六进制字符串转换为float(单精度32位)?
"41973333" -> 1.88999996185302734375E1
"41995C29" -> 1.91700000762939453125E1
"470FC614" -> 3.6806078125E4
Run Code Online (Sandbox Code Playgroud) 我在哪里可以找到PythonMagick的文档和示例?
我在Google上搜索过,但没有找到太多信息.
如何使用PIL检测PNG图像是否具有透明的alpha通道?
img = Image.open('example.png', 'r')
has_alpha = img.mode == 'RGBA'
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我们知道PNG图像是否具有alpha通道,但是如何获得alpha值?
我没有在PIL网站上描述的img.info字典中找到"透明度"键
我正在使用Ubuntu和zlib1g,已经安装了zlibc软件包.
python ×7
django ×4
image ×2
binary ×1
colors ×1
command-line ×1
decimal ×1
hex ×1
imagemagick ×1
many-to-many ×1
mysql ×1
png ×1
postgresql ×1
psycopg2 ×1
rgb ×1
shell ×1
transparent ×1
unicode ×1
utf-8 ×1