小编San*_*eep的帖子

Django无法加载模板标记

templatetags在我的应用程序中创建了一个文件夹,在一个名为的文件中posts.py,我编写了以下代码;

from django.template import Library, Node
from advancedviews.models import Post
register = Library()
class AllPost(Node):
    def render(self,context):
        context['all_posts'] =  Post.objects.all()
        return ''
def get_all_posts(parser,token):
    return AllPost()
get_all_posts = register.tag(get_all_posts) 
Run Code Online (Sandbox Code Playgroud)

现在,我尝试在模板中加载此模板标记;

{% load get_all_posts %}
Run Code Online (Sandbox Code Playgroud)

但这给了我错误, 'get_all_posts' is not a valid tag library: Template library get_all_posts not found, tried django.templatetags.get_all_posts,django.contrib.admin.templatetags.get_all_posts

这个模板中的错误是什么,或者我错过了什么.

django django-templates django-views

3
推荐指数
1
解决办法
4207
查看次数

这个javascript代码有什么问题

在下面的代码中,我试图在用户点击文档时显示警告.由于我用括号做了doAlert(),代码运行时文档加载和警报没有发生任何事件但如果我只是

doAlert

当我点击文档时,它似乎会响应.那么,我是否应该在没有括号的情况下调用javascript中的函数或者这样做的想法是什么.如果我将参数传递给函数怎么办?

<!doctype html>
    <html>
    <head>
    <script>
    function doAlert(){
        alert("Hello");
    }
    function init(){
        document.onclick = doAlert();
    }
    window.onload = init();
    </script>
    </head>
    <body>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript

2
推荐指数
3
解决办法
178
查看次数

jQuery Mobile Iphone应用程序

我正在尝试为iPhone创建一个HTML5 Web应用程序.我正在使用jQuery Mobile.我的应用程序涉及画布.它就像一个使用画布渲染草图的绘图应用程序.用户可以从任何方向在屏幕上滑动,应用程序应该能够找出位置,然后在点上画线.

jQuery Mobile仅为滑动控件提供以下一些基本事件,但我认为我需要对滑动进行更多控制,因为用户可以在任何方向滑动,并且可以是任何像素长.另一方面,我应该能够捕获大部分点,这样我就可以更清晰,更准确地想象绘图.

tap
Triggers after a quick, complete touch event.
taphold
Triggers after a held complete touch event (close to one second).
swipe
Triggers when a horizontal drag of 30px or more (and less than 20px vertically) occurs within 1 second duration.
swipeleft
Triggers when a swipe event occurred moving in the left direction.
swiperight
Triggers when a swipe event occurred moving in the right direction.
Run Code Online (Sandbox Code Playgroud)

我是否应该在画布中为iOs应用程序创建绘图应用程序?任何帮助将不胜感激.

jquery html5 draggable ios jquery-mobile

2
推荐指数
1
解决办法
2968
查看次数

在MATLAB中保存用户定义的类

我在matlab中使用classdef作为,

classdef scores
    %   SCORES Summary of this class goes here
    %   Class for stroring the individual scores array of each of the
    %   comparison of the models and the test files including the number of
    %   coefficients used and number of gaussian 

    properties
        detailed_scores;
        no_of_gauss=0;
    end

    methods
    end
end
Run Code Online (Sandbox Code Playgroud)

创建对象并保存到数组中;

for i=1:99
    score = scores;
    score.detailed_scores = somescore(:,9);
    score.no_of_gauss = i;
    array = [array score];
end
Run Code Online (Sandbox Code Playgroud)

现在,我想将它保存到matfile中;

save('somematfile.mat','array');
Run Code Online (Sandbox Code Playgroud)

是否可以array稍后加载以检索数据?

arrays matlab class multidimensional-array

2
推荐指数
1
解决办法
752
查看次数

核心动画动画图层水平翻转

我有两个视图,我想使用核心动画在两个视图之间切换,为每个视图的图层设置动画.我想要的动画就像提供的动画,UIViewAnimationOptionTransitionFlipFromLeft但我无法做到.我可以使图层旋转180,然后当动画停止时我转换到下一个视图.如何才能做到这一点?

我用的代码如下:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
self.view.layer.zPosition = 100;
CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
[animation setToValue:[NSValue valueWithCATransform3D:transform]];
[animation setDuration:.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setFillMode:kCAFillModeForwards];
[animation setRemovedOnCompletion:YES];
[animation setDelegate:self];

[self.view.layer addAnimation:animation forKey:@"test"];
Run Code Online (Sandbox Code Playgroud)

在代表中我转换到下一个视图.但是,这没有多大意义,动画不像默认动画那样生动.怎么能实现呢?

core-animation objective-c ios

2
推荐指数
2
解决办法
9051
查看次数

RestKit动态嵌套映射

我看到restkit文档相当不错,并且有很多关于对象建模的例子.还有一个嵌套映射的例子,但我发现我的场景与此有点不同.RestKit文档提供了嵌套属性的示例映射,其中包含以下json格式.

RestKit文档中的示例JSON结构:

{
  "blake": {        
    "email": "blake@restkit.org",        
    "favorite_animal": "Monkey"    
  },    
  "sarah": {
    "email": "sarah@restkit.org",   
    "favorite_animal": "Cat"
  }
}
Run Code Online (Sandbox Code Playgroud)

假设我的json有点不同;

我的JSON结构:

{ 
  "id" : 1,
  "author" : "RestKit",
  "blake": {        
    "email": "blake@restkit.org",        
    "favorite_animal": "Monkey"    
  },    
  "sarah": {
    "email": "sarah@restkit.org",   
    "favorite_animal": "Cat"
  }
}
Run Code Online (Sandbox Code Playgroud)

我创建了两个不同的managedobject模型,它具有以下属性和许多关系.

我的结构的两个不同实体Product和creator映射上面的JSON对象.

Product                                           Creator 

identifier          <------------------- >>       name
author                                            email
                                                  favouriteAnimal
Run Code Online (Sandbox Code Playgroud)

现在,我的映射看起来就像产品模型一样;

这就是我映射Product实体的方法,[mapping mapKeyPath:"id"toAttribute:"identifier"]; [mapping mapKeyPath:"author"toAttribute:"author"];

但请注意,映射嵌套字典属性对我不起作用.// [mapping mapKeyOfNestedDictionaryToAttribute:@"creators"];

现在,在作者班.

我无法弄清楚映射上述JSON结构的常用方法.

cocoa-touch core-data objective-c restkit

2
推荐指数
1
解决办法
812
查看次数

UIView 分割过渡

很有可能我只是为此使用了错误的术语,但我一直在寻找是否有 iOS UIView 转换可以拆分视图 (BLUE) 和任何子视图控件以显示另一个视图 (RED) 及其控件。我发现有几篇帖子提到了 2011 年的类似内容,但最近都没有,所以想知道现在是否添加了任何新内容,我们已经升级到 iOS 8。任何指针都将不胜感激。

在此处输入图片说明

transition uiviewcontroller uiview uiviewanimationtransition ios

2
推荐指数
1
解决办法
847
查看次数

使用sqlite与codeigniter奇怪的错误

我正在尝试使用带有codeigniter的sqlite数据库.我在其中创建了一个表,然后将数据库加载到配置文件中;

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'sqlite';
$db['default']['dbprefix'] = '';
Run Code Online (Sandbox Code Playgroud)

并在autoload.php中自动加载了db库,但是我从控制器呈现的视图是空白的,即使没有显示任何错误.当我不自动加载此文件时,viw正确呈现.我不知道这里有什么问题.

php sqlite model codeigniter

1
推荐指数
1
解决办法
1856
查看次数

在核心图形中传递CGFloat数组

核心图形中有许多函数采用指针即.数组的指针,如 CGContextSetFillColor(context,colors); .我必须每次都为数组颜色创建值,然后将指针传递给函数;

CGFloat colors[] = {1.0, 0.0, 0., 1.0};
CGContextSetFillColor(context, colors);
Run Code Online (Sandbox Code Playgroud)

但是,如果我可以将值直接传递给函数,那将会容易得多;

CGContextSetFillColor(context, {1.0, 0.0, 0., 1.0});
Run Code Online (Sandbox Code Playgroud)

上面的语法不正确,编译器抱怨它,我对指针如何在C中工作的理解非常有限.所以我想问一下在同一行中直接传递值的正确方法是什么.

core-graphics ios

1
推荐指数
1
解决办法
319
查看次数

Codeigniter模型错误

我创建了一个新的模型类作为my_model.php内部/models文件夹,并在其中创建一个函数来加载所有元素:

function get_all(){
    $query = $this->db->get('test'); //test is my table 
   return $query->result();
}
Run Code Online (Sandbox Code Playgroud)

在控制器中,我实例化了类并调用了方法;

$this->load->model('my_model');
$res = $this->my_model->get_all();
Run Code Online (Sandbox Code Playgroud)

但是,这引发了我的错误说:

致命错误:在第7行的/var/www/testapp/application/models/my_model.php中调用非对象的成员函数get()

这一行7指向我使用过的代码部分$this->db.我想看到的价值$db,但我认为这是魔术访问__get__set,所以我看不出调用该方法之前,这个属性的值.

我尝试谷歌搜索其他几个案例,但没有一个匹配我的情况,而没有一个可以解决我的问题.

php codeigniter

0
推荐指数
1
解决办法
2101
查看次数