我从存储为的数据库中提取名称myname
.我如何在Django模板中显示这个Myname
,第一个字母是大写的.
请帮助我根据功能的不同来澄清这两个python语句的概念:
sys.exit(0)
os._exit(0)
环境细节:
Server: Amazon ec2 Linux
Web Server: Apache
Web Framework: Django with mod_wsgi
Run Code Online (Sandbox Code Playgroud)
以下我在mysql_err.log文件中找到了.
The InnoDB memory heap is disabled
120823 3:21:40 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120823 3:21:40 InnoDB: Compressed tables use zlib 1.2.3
120823 3:21:40 InnoDB: Using Linux native AIO
120823 3:21:41 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
120823 3:21:41 InnoDB: Completed initialization of buffer pool
120823 3:21:41 InnoDB: Fatal error: cannot allocate memory for the buffer pool …
Run Code Online (Sandbox Code Playgroud) 我生成所有可能的三个字母关键字e.g. aaa, aab, aac.... zzy, zzz
下面是我的代码:
alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
keywords = []
for alpha1 in alphabets:
for alpha2 in alphabets:
for alpha3 in alphabets:
keywords.append(alpha1+alpha2+alpha3)
Run Code Online (Sandbox Code Playgroud)
能否以更加流畅有效的方式实现此功能?
我正在尝试POST一个新的嵌套对象,问题只是创建"顶部"对象(播放列表),但不要创建"ChannelItem"...
我的模特:
class Playlist(models.Model):
provider = models.IntegerField()
channel_id = models.CharField(max_length=100)
channel_version = models.CharField(blank=True, max_length=100)
start = models.DateTimeField()
url = models.CharField(max_length=500)
class ChannelItem(models.Model):
playlist = models.ForeignKey(Playlist, editable=False, related_name='channelitems')
content_id = models.CharField(max_length=100)
content_version = models.CharField(blank=True, max_length=100)
Run Code Online (Sandbox Code Playgroud)
我的序列化器:
class ChannelItemSerializer(serializers.ModelSerializer):
class Meta:
model = ChannelItem
fields = ('content_id', 'content_version')
exclude = ('id')
depth = 1
class PlaylistSerializer(serializers.ModelSerializer):
class Meta:
model = Playlist
fields = ('id', 'provider', 'channel_id', 'channel_version', 'start',
'url', 'channelitems')
depth = 2
channelitems = ChannelItemSerializer()
Run Code Online (Sandbox Code Playgroud)
我使用curl发布以下数据:
'{"provider":125,"channel_id":"xyz", "channel_version":"xsqt",
"start":"2012-12-17T11:04:35","url":"http://192.168.1.83:8080/maaaaa",
"channelitems":[{"content_id":"0.flv", "content_version":"ss"}, …
Run Code Online (Sandbox Code Playgroud) 我看到人们一直在做的事情是:
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
super(ExcitingMan, self).say_hi() # Calling the parent version once done with custom stuff.
Run Code Online (Sandbox Code Playgroud)
我从未见过的人做的事情是:
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
return super(ExcitingMan, self).say_hi() # Returning the value of the call, so as to fulfill the parent class's contract.
Run Code Online (Sandbox Code Playgroud)
这是因为我和所有错误的程序员挂在一起,还是有充分的理由呢?
我一直在努力找到将文档转换为doc,docx,ppt,pptx到pdf的有效方法.到目前为止,我已经试过docsplit和oowriter
,但都采取> 10秒完成任务的pptx文件有大小1.7MB.任何人都可以建议我改进方法的更好方法或建议吗?
我尝试过的:
from subprocess import Popen, PIPE
import time
def convert(src, dst):
d = {'src': src, 'dst': dst}
commands = [
'/usr/bin/docsplit pdf --output %(dst)s %(src)s' % d,
'oowriter --headless -convert-to pdf:writer_pdf_Export %(dst)s %(src)s' % d,
]
for i in range(len(commands)):
command = commands[i]
st = time.time()
process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True) # I am aware of consequences of using `shell=True`
out, err = process.communicate()
errcode = process.returncode
if errcode != 0: …
Run Code Online (Sandbox Code Playgroud) 我试图将html实体转换为unichar,html实体是󮠖
当我尝试执行以下操作时:
unichr(int(976918))
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
Run Code Online (Sandbox Code Playgroud)
似乎它超出了unichar的范围转换.
我有两个模型,命名为Human
和Animal
.Human的主键是Animal模型中的外键.两者各有3列.人体模型有c,e,r列.动物模型有l,i,p列.我在人体模型上运行django查询,就像这样.
result = Human.objects.filter().order_by('r')
Run Code Online (Sandbox Code Playgroud)
result
是一个queryset对象.此对象从我的视图文件发送到django模板页面.在模板页面内部,我循环result
并显示列值.
现在我想做的是,我想p
在同一个循环内,在django模板中获取列的值(它存在于Animal模型中).我们怎么能在django模板页面中做到这一点.
在python文件中,我可以这样做
for i in result:
print i.animal_set.values()[0]['p']
Run Code Online (Sandbox Code Playgroud)
但我想在模板页面中这样做.
python ×7
django ×3
amazon-ec2 ×1
class ×1
compilation ×1
docsplit ×1
html ×1
linux ×1
methods ×1
mysql ×1
overriding ×1
pdf ×1
performance ×1
subclass ×1
ubuntu ×1