我想在每次重启/重装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)
还有其他建议吗?谢谢.
当我在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) 我希望第二行foo代替command not found:
$ alias foo="echo bac" ; foo;
-bash: foo: command not found
$ foo
bac
$
Run Code Online (Sandbox Code Playgroud)
第二行为什么不说foo?使用以下shell进行测试,行为相同:
关于将指针传递给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) 如何监听Tornado循环中stdin上发生的事件?
特别是在龙卷风系统中,我想从stdin读取,对它做出反应,并在stdin关闭时终止.与此同时,Tornado Web服务正在运行相同的进程.
在寻找这个时,我发现最相似的是处理外部生成过程的流.但是,这不是我想要的:我想处理当前进程的i/o流,即具有Web服务器的进程.
在结构上,我的服务器几乎是你好世界的龙卷风,所以我们可以将这个例子作为基础.我只需要添加一个stdin处理程序.
我这里缺乏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.