小编Mot*_*tys的帖子

重启django服务器时清除缓存的最佳位置

我想在每次重启/重装django服务器时刷新memcached.我使用cherrypy进行生产和内置服务器进行开发.

我会在CACHES之后将其添加到settings.py:

from django.core.cache import cache
cache.clear()
Run Code Online (Sandbox Code Playgroud)

但它会进行递归导入:

Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)
make: *** [server] Error 1
Run Code Online (Sandbox Code Playgroud)

还有其他建议吗?谢谢.

python django memcached

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

克隆后立即在OSX上修改Linux内核源代码

当我在OS X上克隆Linux源时,它们会立即被更改,并且git reset --hard不会带回内容.这是一个完整的会议:

$ git clone git://github.com/torvalds/linux.git
$ cd linux
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   include/uapi/linux/netfilter/xt_CONNMARK.h
    modified:   include/uapi/linux/netfilter/xt_DSCP.h
    modified:   include/uapi/linux/netfilter/xt_MARK.h
    modified:   include/uapi/linux/netfilter/xt_RATEEST.h
    modified:   include/uapi/linux/netfilter/xt_TCPMSS.h
    modified:   include/uapi/linux/netfilter_ipv4/ipt_ECN.h
    modified:   include/uapi/linux/netfilter_ipv4/ipt_TTL.h
    modified:   include/uapi/linux/netfilter_ipv6/ip6t_HL.h
    modified:   net/netfilter/xt_DSCP.c
    modified:   net/netfilter/xt_HL.c
    modified:   net/netfilter/xt_RATEEST.c
    modified:   net/netfilter/xt_TCPMSS.c

no changes added to commit …
Run Code Online (Sandbox Code Playgroud)

linux git macos

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

bash:无法在同一行中设置和使用别名

我希望第二行foo代替command not found:

$ alias foo="echo bac" ; foo;
-bash: foo: command not found
$ foo
bac
$
Run Code Online (Sandbox Code Playgroud)

第二行为什么不说foo?使用以下shell进行测试,行为相同:

  • bash 3.2.5
  • zsh 5.0.8
  • 破折号0.5.9
  • busybox 1.25.0

bash zsh busybox dash-shell

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

将指向C数组的指针传递给函数

关于将指针传递给char数组,我有什么误解?

Request pointer in fun: 0x7fffde9aec80
Response pointer in fun: 0x7fffde9aec80
Response pointer: (nil), expected: 0x7fffde9aec80
Response itself: (null), expected: Yadda
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int get_response(char *request, char **response) {
    response = &request;
    printf("Request pointer in fun: %p\n", request);
    printf("Response pointer in fun: %p\n", *response);
    return 0;
}

int main() {
    char *response = NULL, request[] = "Yadda";

    get_response(request, &response);

    printf("Response pointer: %p, expected: %p\n", response, request);
    printf("Response itself: %s, expected: %s\n", response, request);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

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

Kubernetes白皮书

Google是否发布了与Borg类似风格的Kubernetes白皮书?

我知道最终用户文档,它可能解释了很多我正在寻找的东西,但我发现白皮书比最终用户文档更容易阅读.它也更容易转换为死树格式并在一个下午阅读.

computer-science kubernetes

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

用龙卷风处理stdin

如何监听Tornado循环中stdin上发生的事件?

特别是在龙卷风系统中,我想从stdin读取,对它做出反应,并在stdin关闭时终止.与此同时,Tornado Web服务正在运行相同的进程.

在寻找这个时,我发现最相似的是处理外部生成过程的流.但是,这不是我想要的:我想处理当前进程的i/o流,即具有Web服务器的进程.

在结构上,我的服务器几乎是你好世界的龙卷风,所以我们可以将这个例子作为基础.我只需要添加一个stdin处理程序.

python pipe tornado

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

抽象Django模型经理

我这里缺乏Python元编程知识.假设我有以下内容:

class OwnCompanyManager(models.Manager):
    """Only companies of this user"""
    def get_queryset(self, user):
        if user.is_superuser:
            return super(OwnCompanyManager, self).get_queryset()
        return super(OwnCompanyManager, self).get_queryset().filter(
            companyuser__user=user)


class OwnPublisherManager(models.Manager):
    """Only publishers of this user's company"""
    def get_queryset(self, user):
        if user.is_superuser:
            return super(OwnPublisherManager, self).get_queryset()
        return super(OwnPublisherManager, self).get_queryset().filter(
            company__companyuser__user=user)

class Company(models.Model):
    name = models.CharField(max_length=45)

    objects = models.Manager()
    own = OwnCompanyManager()


class Publisher(models.Model):
    company = models.ForeignKey(Company)
    allow_latest_dev = models.BooleanField(default=False)
    domains_blocked = models.BooleanField(default=False)

    objects = models.Manager()
    own = OwnPublisherManager()
Run Code Online (Sandbox Code Playgroud)

我还有很多.我不喜欢复制粘贴样板Own(Publisher|Company|Etcetra)Manager).正如您所见,唯一的变化是在过滤器中.

我怎样才能提取Own(InsertModelNameHere)Manager和使用它Company,Publisher和其他车型?我想在管理器定义中指定过滤器kwargs.

python django metaprogramming django-models

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