小编Paw*_*iak的帖子

记录删除/检查/修改由fileConfig()配置的处理程序

如何使用fileConfig()函数删除/检查/修改为记录器配置的处理程序?

要删除有Logger.removeHandler(hdlr)方法,但如果从文件配置处理器,如何首先获取处理程序?

python logging

50
推荐指数
4
解决办法
3万
查看次数

Python夏令时

如何检查夏令时是否有效?

python time dst

40
推荐指数
3
解决办法
4万
查看次数

如何在Google Chrome中没有滚动条的情况下执行window.open

以下代码在Firefox,IE和Opera中打开没有滚动条新窗口.

    var options = {
        height: 300, // sets the height in pixels of the window.
        width: 300, // sets the width in pixels of the window.
        toolbar: 0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
        scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
        status: 0, // whether a status line appears at the bottom of the window …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome popup

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

Ruby解压缩数组来阻止

settings = [ ['127.0.0.1', 80], ['0.0.0.0', 443] ]
Run Code Online (Sandbox Code Playgroud)

我能怎么做:

settings.each do |ip, port|  
    ...
end
Run Code Online (Sandbox Code Playgroud)

代替:

settings.each do |config|  
    ip, port = *config
    ...
end
Run Code Online (Sandbox Code Playgroud)

ruby arrays multidimensional-array

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

程序结束时__del__

假设在运行时有一个程序包含几个对象.

程序结束时是否调用每个对象的__del__方法?

如果是,我可以举例如下:

class Client:
  __del__( self ):
    disconnect_from_server()
Run Code Online (Sandbox Code Playgroud)

python

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

序列化包含django查询集的对象

Django提供了序列化查询集(django.core.serializers)的工具,但是如何序列化生活在其他对象(如字典)中的查询集呢?

我想序列化以下字典:

dictionary = { 'alfa': queryset1, 'beta': queryset2, } 
Run Code Online (Sandbox Code Playgroud)

我决定使用simplejson(随django一起)这样做.我通过以下方式扩展了simplejson.JSONEncoder:

from django.utils import simplejson
from django.core import serializers

class HandleQuerySets(simplejson.JSONEncoder):
     """ simplejson.JSONEncoder extension: handle querysets """
     def default(self, obj):
         if isinstance(obj, QuerySet):
             return serializers.serialize("json", obj, ensure_ascii=False)

         return simplejson.JSONEncoder.default(self, obj)
Run Code Online (Sandbox Code Playgroud)

然后我这样做了simplejson.dumps( dictionary, cls=HandleQuerySets),但是返回的dicionary看起来像这样:

{ "alfa": "[{\"pk\": 1, \"model\": \"someapp.somemodel\", \"fields\": {\"name\": \"alfa\"}}]",
  "beta": "[{\"pk\": 1, \"model\": \"someapp.somemodel\", \"fields\": {\"name\": \"alfa\"}}]" }
Run Code Online (Sandbox Code Playgroud)

Django生成的JSON作为字符串插入字典,而不是JSON.我究竟做错了什么?

python django json

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

从django到javascript的全局变量

我想一些从我的settings.py变量在每个JavaScript可在我的项目运行.

实现这一目标的最优雅方式是什么?

现在我可以想到两个:

  • 编写上下文处理器并在基本模板中声明这些全局变量.所有模板都必须扩展基本模板.

  • 在动态生成的.js文件中(通过某个视图)声明这些全局变量,并使用<script>基本模板中的标记加载此文件.所有模板都必须扩展基本模板.

我可以在没有基本模板的情况下完成吗?

javascript python django

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

没有回调的ajax

任何javascript框架都有一个功能,其中:

  • 提出AJAX请求
  • 返回响应

    (它不会将回调函数作为参数)

我基本上想要以与C,python或其他任何方式进行SQL查询相同的方式来执行AJAX请求.

javascript ajax

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