我正在开发一个博客应用程序,我希望有一个侧边栏,其中包含博客存在的所有月份的列表,以提供链接到档案页面.此外,我想在月份更改时自动更新,而不是在模板中对其进行硬编码.当然,据我所知,这意味着我必须在每个视图中计算月份列表,并将其传递到每个视图中的每个模板中.
如果可能的话,我想避免这种情况.有没有办法计算列表一次并自动将其应用于每个模板,而不必从每个视图显式传递到模板?
当我在某些地方进行git登录时,输出会搞砸,并且不会让我回到命令行.在我的一些回购中,它工作正常.有任何想法吗?输出粘贴在下面:
[server]$ git log
commit c84acb29115822d94fe0112bacfb835911ffaa11
Author: My Name <myname@server.dreamhost.com>
Date: Sun Feb 14 03:13:05 2010 -0800
Correct spelling mistake
commit 4f613bdddc2b4965b75914c08017a916fa3d07be
Author: My Name <myname@server.dreamhost.com>
Date: Sat Feb 13 08:39:52 2010 -0800
slightly better gradient
commit 96d2a2bb74c287af18a491f616ce784cc30ff1ea
Author: My Name <myname@server.dreamhost.com>
Date: Sat Feb 13 08:31:15 2010 -0800
Add gradient background under menu
commit 80fab463530791e6e9ebb06e475b67211b88a8d4
Author: My Name <myname@server.dreamhost.com>
Date: Fri Feb 12 14:33:04 2010 -0800
change copy back
commit f0952894251854432a6b960d39460a926c819202
Author: My Name <myname@server.dreamhost.com>
Date: Fri Feb 12 …Run Code Online (Sandbox Code Playgroud) 我有一个运行在Apache和Phusion Passenger的生产服务器上的Rails应用程序.当使用Mongrel时,应用程序在本地工作正常,但每当我尝试在生产服务器上加载URL时,它返回HTTP 500.我知道服务器工作正常,因为我可以获取应用程序的静态元素(例如,JavaScript文件) ,样式表,图像)就好了.我还检查了Passenger状态,它正在加载应用程序(它必须是,因为应用程序的500内部服务器错误页面被返回,而不仅仅是默认的Apache).此外,当我通过加载应用程序script/console production并执行类似操作时app.get("/"),也会返回500.
问题是日志文件中没有任何内容可以指示问题.production.log是空的.Apache错误日志也显示Apache没有问题.我很难知道发生了什么,我不知道如何诊断问题.
我知道我可能有点模糊,但任何人都可以提出问题的建议吗?或者至少我可以去诊断一下吗?
我有一段Objective-C代码,如下所示:
- (NSString *)copyData:(NSData *)data
{
NSString *path = [[[self outputDirectory] stringByAppendingPathComponent:@"archive"] stringByAppendingPathExtension:@"zip"];
NSLog(@"Copying data to %@", path);
[data writeToFile:path atomically:NO];
return path;
}
Run Code Online (Sandbox Code Playgroud)
从初始化程序调用代码,如下所示:
- (id)initWithData:(NSData *)data
{
if ((self = [super init]) != nil) {
NSString *path = [self copyData:data]; // Line 41 (referenced in warning, shown below)
return [self initWithContentsOfFile:path];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
运行clang静态分析器时,我得到以下path变量警告:
第41行分配的对象的潜在泄漏并存储在"路径"中
具有+0保留计数的对象返回给调用者,其中预期+1(拥有)保留计数
我糊涂了.我的理解是stringByAppendingPathComponent应该返回一个自动释放的字符串,所以它应该有一个净保留计数为0.(显然我不想保留它.)
我已经尝试改变copyData:以返回以下内容,但它没有消除警告:
return [[path retain] autorelease];
Run Code Online (Sandbox Code Playgroud)
那么这个警告的处理是什么?
而不是计算月和闰年来做这个计算.有没有办法检查使用一些Apple内部API这样做?
我发现Java有这样的东西:
calendar.getActualMaximum(calendar.DAY_OF_MONTH)
Run Code Online (Sandbox Code Playgroud)
Objective C有什么类似的东西吗?你.
我有一组Django模型,如下图所示(反向关系的名称显示在黄色气泡中):
Django模型http://mipadi.cbstaff.com/images/misc/people_django.jpg
在每个关系中,a Person可以具有0个或更多个项目.
此外,该slug领域(不幸的是)不是唯一的; 多个Person记录可能具有相同的段塞字段.基本上这些记录是重复的.
我想获得满足以下条件的所有记录的列表:所有重复记录(即具有相同的段塞),其中至少一个EntryOR至少一个AudioOR至少一个EpisodeOR至少一个Article.
到目前为止,我有以下查询:
Person.objects.values('slug').annotate(num_records=Count('slug')).filter(num_records__gt=1)
Run Code Online (Sandbox Code Playgroud)
这将所有记录分组slug,然后添加一个num_records属性,说明有多少记录有那个slug,但是没有执行额外的过滤(我甚至不知道这是否会正常工作,因为,给定一组重复记录,一个人可能有,例如,和Entry另一个人可能有a Article).
简而言之,我想找到所有重复的记录,并将它们及其相关模型折叠到一个记录中.
使用Django最好的方法是什么?
我正在编写一个框架(称为Lighthouse.framework),反过来,它使用来自另一个框架的代码(准确地说是RegexKit.framework).我已将RegexKit.framework复制到我自己的框架中,因此它具有如下结构:
Lighthouse.framework/
Versions/
A/
Frameworks/
RegexKit.framework
Lighthouse
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行使用Lighthouse.framework(我的框架)的应用程序时,我收到以下错误:
dyld:未加载库:@executable_path /../ Frameworks/RegexKit.framework/Versions/A/RegexKit
参考自:/Users/mdippery/Developer/Projects/Current/lighthouse/build/Debug/Lighthouse.framework/Versions/A/Lighthouse
原因:找不到图像
显然,加载器没有找到RegexKit.
以下是加载器期望加载的路径,礼貌otool:
build/Debug/Lighthouse.framework/Versions/A/Lighthouse:
/Users/mdippery/Library/Frameworks/Lighthouse.framework/Versions/A/Lighthouse (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0)
@executable_path/../Frameworks/RegexKit.framework/Versions/A/RegexKit (compatibility version 0.4.0, current version 0.6.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.19.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 677.26.0)
Run Code Online (Sandbox Code Playgroud)
我可以在另一个框架中包含一个框架吗?这是正确的方法吗?我该如何解决我的错误?
这些天我一直遇到github的问题,我在github上创建了一个新的存储库,然后从本地机器我尝试将我的代码推送到github:
git remote add origin git@github.com:tmi/logger.git fatal: remote origin already exists git push origin master ssh: github.com:uhdyi: no address associated with name fatal: the remote end hung up unexpectedly ssh git -v OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Fed 2007 ssh: git: no address associated with name ssh git@github.com Enter passphrase for key '/c/Documents and Settings/tmi/.ssh/id_rsa': Error: HI, tmi! you've successfullly authenticated, but GitHub doesn not provide shell access connection to github.com closed git push origin master ssh: github.com:uhdyi: no address associated …
我通过以下方法在MySQL数据库中创建了一个表:
CREATE TABLE `newsubscriptions_orderspecification` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`display_name` varchar(256) NOT NULL,
`sub_def_id` integer UNSIGNED NOT NULL,
`source_code_id` integer UNSIGNED NOT NULL,
`order_code_id` integer UNSIGNED NOT NULL,
`rate` numeric(5, 2) NOT NULL,
`type` varchar(4) NOT NULL,
`region` varchar(4) NOT NULL,
`term` varchar(4) NOT NULL,
`buyer_type` varchar(4) NOT NULL,
`is_active` bool NOT NULL,
UNIQUE (`sub_def_id`, `buyer_type`, `rate`, `is_active`)
)
;
Run Code Online (Sandbox Code Playgroud)
如何删除唯一性约束?