我很好奇是否有合理的方法来使用(惊人的)django-debug-toolbar和AJAX查询.
例如,我使用带有一堆参数的jQuery $ .get来命中Django URL并将其加载到内联中.如果我有错误,它不会在工具栏上注册.我也不能通过复制AJAX URL来使用它,因为DDT附加到响应的body标签,并且包含具有AJAX响应的body标签没有任何意义.
任何方向都会有所帮助!谢谢!
似乎当我的应用加载时,它不知道它的当前方向:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
NSLog(@"portrait");// only works after a rotation, not on loading app
}
Run Code Online (Sandbox Code Playgroud)
一旦我旋转设备,我得到一个正确的方向,但当我加载应用程序,而不改变方向,似乎使用[[UIDevice currentDevice] orientation]不知道当前的方向.
我第一次加载应用程序时是否还有另一种检查方法?
我写了一个视图,它响应来自浏览器的ajax请求.它是这样写的 -
@login_required
def no_response(request):
params = request.has_key("params")
if params:
# do processing
var = RequestContext(request, {vars})
return render_to_response('some_template.html', var)
else: #some error
# I want to send an empty string so that the
# client-side javascript can display some error string.
return render_to_response("") #this throws an error without a template.
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
以下是我在客户端处理服务器响应的方法 -
$.ajax
({
type : "GET",
url : url_sr,
dataType : "html",
cache : false,
success : function(response)
{
if(response)
$("#resp").html(response);
else
$("#resp").html("<div id='no'>No data</div>");
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试检查一个字符是否属于无效字符的列表/数组.
来自Python背景,我曾经只能说:
for c in string:
if c in invalid_characters:
#do stuff, etc
Run Code Online (Sandbox Code Playgroud)
如何使用常规C char数组执行此操作?
我想使用request.POST['xzy']列表获取多选复选框的值.这是我的模型和模板代码.
我的模特
class Recommend(models.Model):
user=models.ForeignKey(User)
book=models.ForeignKey(BookModel)
friends=models.ManyToManyField(User, related_name="recommended")
Run Code Online (Sandbox Code Playgroud)
我的模板
{% for friend in friends %}
<input type="checkbox" name="recommendations" id="option{{friend.id}}" value={{friend.username}} />
<label for="option{{friend.id}}"><b>{{friend.username}}</b></label><br />
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我的查看代码
if request.method == 'POST':
recommendations=request.POST['recommendations']
Run Code Online (Sandbox Code Playgroud)
在这里,我希望"推荐"成为包含所有朋友ID的列表,但是这里只是被覆盖并且仅包含在最后一次for循环迭代中分配的值.我怎么解决这个问题.绝望地需要帮助.谢谢.
我想将日期与Django中的当前日期进行比较,最好是在模板中,但在渲染模板之前也可以这样做.如果日期已经过去,我想说"过去",如果是将来,我想给出日期.
我希望有人可以这样做:
{% if listing.date <= now %}
In the past
{% else %}
{{ listing.date|date:"d M Y" }}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
现在是今天的日期,但这不起作用.我在Django文档中找不到任何相关内容.谁能提出一些建议?
我刚刚开始学习Python并且在Python中遇到了"命名空间"概念.虽然我得到了它的概念,但我无法理解这个概念的严重性.
网上的一些浏览显示,针对PHP的一个原因是它没有对命名空间的本机支持.
有人可以解释如何使用命名空间以及此功能如何使编程更好(不仅仅是在Python中,因为我假设命名空间不是限于特定语言的概念).
我主要来自Java和C编程背景.
我记得在某处可以真正优化和加速代码的某些部分,程序员用汇编语言编写该部分.我的问题是 -
我正在努力理解这个概念,非常感谢任何帮助或链接.
更新:根据dbemerlin的要求改写第3点 - 因为您可能能够编写比编译器生成的更有效的汇编代码,但除非您是汇编专家,否则您的代码运行速度会慢,因为编译器通常会比大多数人更好地优化代码.
我有以下代码:
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect r = [btn frame];
r.origin.y -= 40;
[btn setFrame: r];
}
completion:^(BOOL done){
if(done){
[UIView animateWithDuration:0.3
delay:1
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect r = [btn frame];
r.origin.y += 40;
[btn setFrame: r];
}
completion:^(BOOL done){if(done) zombiePopping = 0; }];
}
}];
Run Code Online (Sandbox Code Playgroud)
问题是,即使我正在使用UIViewAnimationOptionAllowInteraction,按钮也不会在动画时响应触摸,这对我来说有点奇怪.
也许最好用Core Animation来完成这项工作?如果是的话,我该怎么做呢?
我在我的主视图,可同时接收应用程序touchesBegan和touchesMoved,因此,需要在单手指触摸,并拖动.我想实现一个UIScrollView,我有它的工作,但它覆盖了拖动,因此我的contentView永远不会收到它们.我想实现一个UIScrollview,其中双指拖动指示滚动,并且单指拖动事件被传递到我的内容视图,因此它正常执行.我需要创建自己的子类UIScrollView吗?
这是我appDelegate实现的代码UIScrollView.
@implementation MusicGridAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize scrollView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
//[application setStatusBarHidden:YES animated:NO];
//[window addSubview:viewController.view];
scrollView.contentSize = CGSizeMake(720, 480);
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.delegate = self;
[scrollView addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[scrollView release];
[window release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud) python ×5
django ×4
iphone ×3
c ×2
ios ×2
objective-c ×2
ajax ×1
arrays ×1
assembly ×1
c++ ×1
char ×1
checkbox ×1
django-views ×1
namespaces ×1
optimization ×1
string ×1
uidevice ×1
uiscrollview ×1