小编ale*_*.tu的帖子

如何在django rest视图中使用login_required

我试图在特定视图中使用自定义登录URL

@login_required(login_url='/account/login/')
class home(APIView):
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, format=None):
        template = get_template(template_name='myapp/template.html')
        return Response({}, template_name=template.template.name)
Run Code Online (Sandbox Code Playgroud)

但追溯显示

File "django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
TypeError: __init__() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)

是否可以在基于类的视图中使用自定义login_required?

谢谢!

python django django-rest-framework

10
推荐指数
2
解决办法
7131
查看次数

解析Android中的LinkedList时的java.lang.AbstractMethodError

我想窥探android中的Linkedlist.

List list = new LinkedList();
List spyData = Mockito.spy(list);
spyData.add("xxxx");
Run Code Online (Sandbox Code Playgroud)

但是,发生了异常.

java.lang.AbstractMethodError: abstract method "boolean org.mockito.internal.invocation.AbstractAwareMethod.isAbstract()"
    at     org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:109)
    at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
    at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
    at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
    at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
    at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
    at LinkedList_Proxy.add(LinkedList_Proxy.generated)
    at com.app.test.testmethod(mytest.java:202)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1858)
Run Code Online (Sandbox Code Playgroud)

libs的依赖关系是

dexmaker-1.2.jar
dexmaker-mockito-1.2.jar
mockito-core-1.10.19.jar
Run Code Online (Sandbox Code Playgroud)

即使我更新mockito-core-1.10.19.jarmockito-core-2.0.31-beta.jar,

问题依然存在.

但是Mockito.mock(Linkedlist.class)没关系,我对这个问题没有任何想法.

谢谢.

java android mockito dexmaker android-instrumentation

7
推荐指数
2
解决办法
1517
查看次数

为什么faster-rcnn端到端训练只做近似?

在更快的 rcnn ( https://arxiv.org/abs/1506.01497 ) 中,

有两种方法可以训练网络。

一种方法是联合训练 rpn 和 fast rcnn。

另一种方法是以端到端的方式训练 rpn 和 fast rcnn。

但是作者表示,在端到端的训练中,结果只是近似于联合训练。

仅近似的原因是

该解决方案忽略了提案框坐标的导数,这些坐标也是网络响应,因此是近似的。

但是,根据网络定义(https://github.com/rbgirshick/py-faster-rcnn/blob/master/models/pascal_voc/VGG16/faster_rcnn_end2end/train.prototxt),rpn的边界框回归为每个更新训练迭代,所以它不会被忽略。

那么,为什么它忽略了提案框坐标的导数?这意味着什么?

image-processing object-detection deep-learning

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

jacoco:对于报告生成,必须在运行时使用相同的类文件

我一直在研究android项目,并使用roboletric和powermock来完成unitTest.

当我跑gradle jacocoTestReport,它会显示

[ant:jacocoReport] Classes in bundle 'app' do no match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class com/my/app/MyClass does not match.
Run Code Online (Sandbox Code Playgroud)

我使用powermock来模拟Myclass.java中的静态方法

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
@PrepareForTest(MyClass.class)
public class TheTest {

    @Rule
    public PowerMockRule rule = new PowerMockRule();

    @Test
    public void test1() throws Exception {
        PowerMockito.mockStatic(MyClass.class);
        // do something
    }
}
Run Code Online (Sandbox Code Playgroud)

build.gradle如下所示

apply plugin: 'jacoco' …
Run Code Online (Sandbox Code Playgroud)

java android powermock gradle jacoco

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

对shared_ptr中的const int的未定义引用

我有一个Config课程

// config.hpp

class Config {
  public:
    static constexpr int a = 1;
    static constexpr int b = 1;
}
Run Code Online (Sandbox Code Playgroud)

并包含在main.cpp中

// main.cpp
#include "config.hpp"
int main () {
  std::cout << Config::a << std::endl; // this is ok
  std::shared_ptr<otherClass> stream = std::make_shared<otherClass>( 
Config::a); // compile error
}
Run Code Online (Sandbox Code Playgroud)

和编译器说 undefined reference to Config::a

它在使用时起作用cout,但在shared_ptr构造函数中不起作用.

我不知道为什么会这样.

c++ definition one-definition-rule constexpr c++17

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

在最新的 CMAKE 中找不到 CUDA_INCLUDE_DIRS

由于在 CMAKE 3.10 中,默认情况下支持 CUDA 宏(https://cmake.org/cmake/help/latest/module/FindCUDA.html)。

但我找不到变量 CUDA_INCLUDE_DIRS

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(cmake_and_cuda LANGUAGES CXX CUDA)

message(${CUDA_INCLUDE_DIRS})
Run Code Online (Sandbox Code Playgroud)

错误是

-- The CXX compiler identification is GNU 5.4.0
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for …
Run Code Online (Sandbox Code Playgroud)

cuda cmake

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

无法从 pybind11 中的静态函数返回shared_ptr

我尝试绑定一个静态函数,该函数返回指向另一个类的shared_ptr。

这是示例代码

class Example {
  public:
    Example() {}
    ~Example() {}
};

class ABC {
  public:
    static std::shared_ptr<Example> get_example() {std::make_shared<Example();}
 };

void init_abc(py::module & m) {
  py::class_<Example>(m, "Example")
    .def(py::init<>());

  py::class_<ABC>(m, "ABC")
    .def_static("get_example", &ABC::get_example);
}
Run Code Online (Sandbox Code Playgroud)

这是Python的一面

example = my_module.ABC.get_example()
Run Code Online (Sandbox Code Playgroud)

然而,python 端抛出了分段错误。

任何想法?

c++ python pybind11

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

是否可以在Android SELinux中使用包名作为域名?

Android SELinux(或者你可以说是SEAndroid)定义了许多域,包括system_app,platform_app,isolated_app等.

每个域具有不同的含义,例如,system_app包括共享系统uid的所有应用程序,platform_app包括签署平台密钥的所有应用程序.

所有SE文件都位于external/sepolicy中,我可以从这些文件中修改规则.

是否可以定义指向指定包名称的新域(例如,com.google.android.music)?

我没有找到任何关于这方面的文件或例子,所以我不知道该怎么做.

我将不胜感激任何建议或意见.

谢谢.

android selinux

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

无法在 pybind11 中绑定重载的静态成员函数

我尝试使用 pybind11 绑定静态重载函数,但遇到了一些问题。

\n\n

这是示例代码

\n\n
#include <pybind11/pybind11.h>\n\nnamespace py = pybind11;\n\nclass TESTDB {\n  public:\n    static void aaaa(int a, int b) {printf("aaaaa");};\n    static void aaaa(int a) {printf("xxxxx");};\n};\n\nPYBIND11_MODULE(example, m) {\n\n\n  py::class_<TESTDB>(m, "db")\n     .def_static("aaaa", (void (TESTDB::*)(int, int)) &TESTDB::aaaa);\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

但由于以下原因无法编译

\n\n
error: no matches converting function \xe2\x80\x98aaaa\xe2\x80\x99 to type \xe2\x80\x98void (class TESTDB::*)(int, int)\xe2\x80\x99\n   .def_static("aaaa", (void (TESTDB::*)(int, int)) &TESTDB::aaaa);\n note: candidates are: static void TESTDB::aaaa(int)\n static void aaaa(int a) {printf("xxxxx");};\n note:                 static void TESTDB::aaaa(int, int)\n static void aaaa(int a, int b) {printf("aaaaa");};\n
Run Code Online (Sandbox Code Playgroud)\n\n

任何想法? …

c++ python function-pointers pointer-to-member pybind11

2
推荐指数
1
解决办法
2456
查看次数

使用 unique_ptr 保护析构函数

我正在尝试从第三方库调用 API。

当我想将 unique_ptr 与具有受保护析构函数的类一起使用时会出现问题。

这是例子,

#include <memory>
#include <iostream>

using namespace std;

class Parent {  
  public:  
    Parent () //Constructor
    {
        cout << "\n Parent constructor called\n" << endl;
    }
  protected:
    ~ Parent() //Dtor
    {
        cout << "\n Parent destructor called\n" << endl;
    }
};

class Child : public Parent 
{
  public:
    Child () //Ctor
    {
        cout << "\nChild constructor called\n" << endl;
    }
    ~Child() //dtor
    {
        cout << "\nChild destructor called\n" << endl;
    }
};

Parent* get() {
  return …
Run Code Online (Sandbox Code Playgroud)

c++

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