我有这样的功能friend_exists:
def friend_exists(request, pid):
result = False
try:
user = Friend.objects.get(pid=pid)
except Friend.DoesNotExist:
pass
if user:
result = True
return result
Run Code Online (Sandbox Code Playgroud)
我从我的其他函数调用它:
exists = friend_exists(form.cleaned_data['pid'])
Run Code Online (Sandbox Code Playgroud)
哪里pid = u'12345678'.为什么我得到:
Exception Type: TypeError at /user/register/
Exception Value: friend_exists() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一些关键事件,也对应于按钮.我必须设置/调用按钮看起来很沮丧(更改状态?)半秒钟的属性/方法?
我想澄清一下Objective-C类的不同实例是否共享在方法内发生的静态变量,或者每个实例是否都有自己的副本:
- (void) myMethod {
static int myVar = 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个程序,需要处理多个音频输入。
我目前正在使用AudioQueues来获取输入,但这仅来自默认输入设备。
有什么办法可以:
我知道我可以在Core-Audio中使用kAudioHardwarePropertyDevices来获取输出设备的列表,我可以使用类似的输入设备吗?
我正在尝试找出在Mongo中构建数据的最佳方法,以模拟SQL中的简单连接或子查询.
假设我有经典的用户和帖子示例,其中一个集合中的用户和另一个集合中的帖子.我想查找所有城市是"伦敦"的用户的帖子.
我在这个问题中简化了一些事情,在我的真实场景中,将帖子作为数组存储在用户文档中将无法正常工作,因为每个用户不断插入1000个"帖子".
Mongos $ in运营商可以帮忙吗?$ $可以处理10,000,000个条目的数组吗?
CODE SNIPPET 1和CODE SNIPPET 2有什么区别?
;CODE SNIPPET 1
(define i 0)
(do ()
((= i 5)) ; Two sets of parentheses
(display i)
(set! i (+ i 1)))
;CODE SNIPPET 2
(define i 0)
(do ()
(= i 5) ; One set of parentheses
(display i)
(set! i (+ i 1)))
Run Code Online (Sandbox Code Playgroud)
第一个代码片段产生01234,第二个代码片段产生5.发生了什么?额外的一组括号有什么作用?另外,我见过[(= i 50)]用而不是((= i 5)).有区别吗?谢谢!
我在模型中有一个 JSONField ( http://djangosnippets.org/snippets/1478/ ),我试图找出向管理员用户显示数据而不是 json 的最佳方式。
有谁知道在 django admin 中执行此操作的最佳方法?
例如,我想
{u'field_user_name': u'foo bar', u'field_email': u'foo@bar.com'}
显示为
field_user_name = foo bar
field_email = foo@bar.com
Run Code Online (Sandbox Code Playgroud) 好吧,所以我有这些代码,当我提出请求时,我想包含一些HTTP标头信息.我该怎么做呢?
public boolean call(String apiCall) {
if (this.apiCalls.containsKey(apiCall)) {
try{
URL url = this.apiCalls.get(apiCall);
url = new URL(url.toString() + "?memberid=76710");
URLConnection urlConn = url.openConnection();
InputStream is = urlConn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
this.responseResultText = new String(baf.toByteArray());
return true;
} catch(Exception e){
this.responseResultText = e.getMessage();
return false;
}
}
this.responseResultText = "API call " + apiCall + " doesn't exist.";
return false;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试加载保存到本地文件系统的m3u8文件,但MPMoviePlayerController拒绝播放它,引用"m3u8不是支持的媒体类型".但是,当我在远程媒体服务器上访问时,相同的m3u8文件可以正常播放.有没有可用于播放本地m3u8文件的解决方法?
我一直在研究一个新的应用程序,并且真的希望实现一次滑动以在我的应用程序中显示更多选项菜单.我进行了搜索和搜索,但似乎没有其他人成功地使其工作(除了Loren).我要做的是滑动单元格,同时使用CABasicAnimation将其推送到x:320,并在此下面添加一个子视图,其中包含按钮等.我正在使用willBeginEditing来检测滑动以避免子类化.这是代码:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.0;
theAnimation.repeatCount=0;
theAnimation.autoreverses=NO;
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:+320];
[cell.layer addAnimation:theAnimation forKey:@"animateLayer"];
CGRect frame = CGRectMake(0, 59 * indexPath.row, 320, 59);
UIView *menu = [[[UIView alloc] initWithFrame:frame] autorelease];
NSString *path = [NSString stringWithFormat:@"%@%@",
[[NSBundle mainBundle] resourcePath],
@"/flick.wav"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
self.menu.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dots.png"]];
[self.view addSubview:menu];
[self.view sendSubviewToBack:menu];
}
- (void)animationDidStop:(NSString*)animationID …Run Code Online (Sandbox Code Playgroud) django ×2
iphone ×2
objective-c ×2
audio ×1
audiotoolbox ×1
cocoa ×1
cocoa-touch ×1
core-audio ×1
django-admin ×1
do-loops ×1
function ×1
java ×1
json ×1
macos ×1
mongodb ×1
nsbutton ×1
python ×1
scheme ×1
uikit ×1
uitableview ×1