小编Sam*_*des的帖子

python 中的多重继承与 super

class Parent1(object):
    def foo(self):
        print "P1 foo"

    def bar(self):
        print "P1 bar"


class Parent2(object):
    def foo(self):
        print "P2 foo"

    def bar(self):
        print "P2 bar"



class Child(Parent1, Parent2):
    def foo(self):
        super(Parent1, self).foo()

    def bar(self):
        super(Parent2, self).bar()

c = Child() 
c.foo()
c.bar()
Run Code Online (Sandbox Code Playgroud)

目的是从 Parent1 继承 foo(),从 Parent2 继承 bar()。但是 c.foo() 对parent2 和 c.bar() 结果是错误的。请指出问题并提供解决方案。

python oop multiple-inheritance python-2.7

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

Django Logger:如何记录用户名

我想实现我的Django项目(日志django 1.11Python 3.6)。我正在使用默认的Django记录器。

要获取username日志,我使用了django-requestlogging 1.0.1。到目前为止,除admin超级用户外,我没有任何其他用户。

当我在前端尝试GET请求时,发生错误,提示 'LogSetupMiddleware' is not callable.

  1. 此错误的原因是什么?如何使记录工作?

  2. 如何获取AnonymousUser日志?

文件settings.py片段:

INSTALLED_APPS= [
    ...
    'django_requestlogging',
]

MIDDLEWARE = [
    ...
    'django_requestlogging.middleware.LogSetupMiddleware',
    ...
]

LOGGING = {
    'version': 1,
    'formatters': {
        'standard' : {
            'format': '%(asctime)s %(username)s %(request_method)s',
        }, 
    },
}
Run Code Online (Sandbox Code Playgroud)

django django-middleware python-3.x django-rest-framework

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

response.get('X-Frame-Options') 不是 None :当传递两个以上查询参数时

我正在尝试通过 DRF 进行 GET API 调用。

我的网址如下所示: http://127.0.0.1: 8000/patha/pathb/pathc/pathd/cd7701b?name=IT&size=20&workflow=rv

但它产生了一个错误:

   if response.get('X-Frame-Options') is not None:
   AttributeError: 'NoneType' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

但是当我只是发送两个查询参数时:

  http://127.0.0.1:8000/patha/pathb/pathc/pathd/cd007b?name=IT&size=20
Run Code Online (Sandbox Code Playgroud)

或者,这三个参数中的两个参数的任意组合将到达视图方法。

我的视图方法如下所示:

 class MyRtList(generics.ListAPIView, customMixin):
 ...
 # Here I'd like to use all three inputs:
 # cd007b
 # `name` and `size`
Run Code Online (Sandbox Code Playgroud)

和 urls.py:

    url(r'patha/pathb/pathc/(?P<name>[^/]+)?$',views.MyRtList.as_view()),    
Run Code Online (Sandbox Code Playgroud)

我正在经历医生。使用 param1 和 param2 显示的示例。最多可以使用两个查询参数吗?是否禁止使用像 cd007b 和查询参数这样的混合数据?因为它会被 3 个参数卡住,但不会被 2 个参数卡住。

哪里出了问题?

query-string x-frame-options django-rest-framework

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