我在 views.py 中有这个功能(与联系表格有关)。我需要将所有输入和输出记录到一个临时文件中,但我不知道如何在 django 中做到这一点。出现新错误:找不到记录器“farah”的处理程序
设置.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'farah': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/home/farah/update/farah.log',
},
},
'loggers': {
'django': {
'handlers': ['farah'],
'level': 'DEBUG',
'propagate': True,
},
},
}
Run Code Online (Sandbox Code Playgroud)
views.py 中的函数:logger = logging.getLogger('farah') def contact(request):
form = FeedbackForm(request.POST or None)
if form.is_valid():
recaptcha_response = request.POST.get('g-recaptcha-response')
url = 'https://www.google.com/recaptcha/api/siteverify'
values = {
'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
'response': recaptcha_response
}
data = urllib.urlencode(values).encode()
req = urllib2.Request(url, data=data)
response = urllib2.urlopen(req)
result = json.loads(response.read().decode())
''' …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Django 的网站。我们的网站始终会重定向为 https。在本地主机上它会导致问题。错误是:
**An error occurred during a connection to 127.0.0.1:8000. SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG**
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题呢?拜托我需要你的帮忙。这个问题以前不存在。到目前为止我还找不到解决方案。
nginx的配置是:
server {
listen 80;
listen [::]:80;
server_name www.website.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_max_body_size 6m;
if ($scheme = http) {
return 301 https://website.com$request_uri;
}
location /static {
alias /home/website/staticfiles;
autoindex on;
expires max;
gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml
application/xml application/xml+rss text/javascript;
}
location /media {
alias /home/website/media;
autoindex on;
expires max; …Run Code Online (Sandbox Code Playgroud) 我有两个文件..我使用循环法从第一个文件读取一行,从第二个文件读取第二行.
def roundrobin(*iterables):
pending = len(iterables)
nexts = cycle(iter(it).next for it in iterables)
while pending:
try:
for next in nexts:
yield next()
except StopIteration:
pending -= 1
nexts = cycle(islice(nexts, pending))
Run Code Online (Sandbox Code Playgroud)
然后:
c= roundrobin(a, b)
Run Code Online (Sandbox Code Playgroud)
a和b是列表.如何循环排序?我尝试使用
c.sort()
Run Code Online (Sandbox Code Playgroud)
但错误是
AttributeError:'generator'对象没有属性'sort'
我需要根据第一列的元素(d/M/Y)对c进行排序