小编Dmi*_*mov的帖子

Why python finds module instead of package if they have the same name?

Here is my directory structure:

/home/dmugtasimov/tmp/name-res
    root
        tests
            __init__.py
            test_1.py
        __init__.py
        classes.py
        extra.py
        root.py
Run Code Online (Sandbox Code Playgroud)

File contents: root/tests/_init_.py

import os, sys
ROOT_DIRECTORY = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                             '../..'))
if not sys.path or ROOT_DIRECTORY not in sys.path:
    sys.path.insert(0, ROOT_DIRECTORY)
# These imports are required for unittest to find test modules in package properly
from root.tests import test_1
Run Code Online (Sandbox Code Playgroud)

root/tests/test_1.py

import unittest
from root.classes import Class1
class Tests(unittest.TestCase):
    pass
Run Code Online (Sandbox Code Playgroud)

root/_init_.py - empty
root/classes.py

import os, sys
ROOT_DIRECTORY = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if not sys.path …
Run Code Online (Sandbox Code Playgroud)

python import module package sys.path

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

如何在nginx上拒绝使用404

我想通过提供deny/allow指令来保护nginx中的某些位置,但我不希望局外人知道位置被拒绝.我希望局外人获得404,而不是403 http代码.我的配置代码段是

location /admin/ {
    uwsgi_pass myupstream1;
    include /path/to/uwsgi_params;

    allow 127.0.0.1;
    deny all;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试访问/ admin/nginx使用HTTP 403响应时,但我希望它以HTTP 404响应.任何配方都可以吗?

security nginx http-status-code-403 http-status-code-404

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