鉴于:
a = 1
b = 10
c = 100
Run Code Online (Sandbox Code Playgroud)
如何为少于两位数的所有数字显示前导零?
那是,
01
10
100
Run Code Online (Sandbox Code Playgroud) 假设我有一个表格
class SampleClass(forms.Form):
name = forms.CharField(max_length=30)
age = forms.IntegerField()
django_hacker = forms.BooleanField(required=False)
Run Code Online (Sandbox Code Playgroud)
有没有办法让我在每个字段上定义css类,以便我可以在渲染页面中使用基于类的jQuery?
我希望不必手动构建表单.
当使用启动django应用程序时python manage.py shell,我得到一个InteractiveConsole shell - 我可以使用Tab完成等.
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
Run Code Online (Sandbox Code Playgroud)
刚刚启动python解释器时python,它不提供制表符完成.
有人能告诉我django正在做什么来给我一个交互式控制台,或者我需要做什么来启动没有django应用程序的交互式控制台?
现在我的Vagrantfile中有以下内容:
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "chef-redis::source"
chef.add_recipe "openssl"
chef.add_recipe "git"
chef.add_recipe "postgresql::server"
chef.add_recipe "postgresql::client"
end
Run Code Online (Sandbox Code Playgroud)
为了安装添加到我的recipe_list的软件,我需要让VM 在安装其他软件之前发布apt-get更新.
我的印象是,这是'apt'配方的一个特点 - 它会首先运行更新.
我做流浪汉时的输出是:
[Sat, 11 Feb 2012 22:20:03 -0800] INFO: *** Chef 0.10.2 ***
[Sat, 11 Feb 2012 22:20:03 -0800] INFO: Setting the run_list to ["recipe[apt]", "recipe[build-essential]", "recipe[chef-redis::source]", "recipe[openssl]", "recipe[git]", "recipe[postgresql::server]", "recipe[postgresql::client]", "recipe[vagrant-main]"] from JSON
[Sat, 11 Feb 2012 22:20:03 -0800] INFO: Run List is [recipe[apt], recipe[build-essential], recipe[chef-redis::source], recipe[openssl], recipe[git], …Run Code Online (Sandbox Code Playgroud) class Foo(models.Model):
title = models.CharField(max_length=20)
slug = models.SlugField()
Run Code Online (Sandbox Code Playgroud)
是否有一种内置的方法可以根据标题让slug字段自动填充?也许在管理员和管理员之外.
有没有办法在Wordpress中使用THE LOOP来加载页面而不是帖子?
我希望能够查询一组子页面,然后使用THE LOOP函数调用它 - 比如the_permalink()和the_title().
有没有办法做到这一点?我在query_posts()文档中没有看到任何内容.
我需要一些方法来为表单字段的label_tag()方法的输出添加一个类属性.
我看到有能力传入一个attrs字典,我已经在shell中测试了它,我可以做类似的事情:
for field in form:
print field.label_tag(attrs{'class':'Foo'})
Run Code Online (Sandbox Code Playgroud)
我会在输出中看到class ='Foo',但是我没有看到从模板中添加attrs参数的方法 - 实际上,模板是专门针对它设计的,不是吗?
我的表单定义中有一种方法来定义要在标签中显示的类吗?
在表单中,我可以执行以下操作为输入提供类
self.fields['some_field'].widget.attrs['class'] = 'Foo'
Run Code Online (Sandbox Code Playgroud)
我只需要输出它的类.
我希望从我的视图中动态更新ModelForm的内联Meta类.尽管此代码似乎更新在Meta类中的排除列表,从输出as_p(),as_ul()等不反映更新的Meta排除.
我假设在创建ModelForm时不是在as_*()调用时生成html .有没有办法强制更新HTML?
这甚至是最好的方法吗?我只是假设这应该工作.
思考?
from django.forms import ModelForm
from testprogram.online_bookings.models import Passenger
class PassengerInfoForm(ModelForm):
def set_form_excludes(self, exclude_list):
self.Meta.exclude = excludes_list
class Meta:
model = Passenger
exclude = []
Run Code Online (Sandbox Code Playgroud) 我正在使用xmlrpclib.ServerProxy对远程服务器进行RPC调用.如果没有到服务器的网络连接,则需要默认的10秒钟才能将socket.gaierror返回给我的程序.
在没有网络连接的情况下进行开发或者远程服务器关闭时,这很烦人.有没有办法更新我的ServerProxy对象上的超时?
我看不到一个明确的方法来访问套接字来更新它.
有没有办法在序列化Django模型类时将任何@property定义传递给json序列化程序?
例:
class FooBar(object.Model)
name = models.CharField(...)
@property
def foo(self):
return "My name is %s" %self.name
Run Code Online (Sandbox Code Playgroud)
想序列化为:
[{
'name' : 'Test User',
'foo' : 'My name is Test User',
},]
Run Code Online (Sandbox Code Playgroud)