我想这样做,以便如果用户在 URL 中输入无效路径,它会自动将其重定向到主页。
像这样的东西:
<BrowserRouter>
<Routes>
<Route exact path="/" element={<Home />}/>
<Route exact path="/page" element={<page />}/>
<Route path="*" /*Go to path - "/" */ />
</Routes>
</BrowserRouter>
Run Code Online (Sandbox Code Playgroud) 我有一个具有静态方法的类,我想在该类中使用另一个静态方法来调用该方法,但它返回NameError: name ''method_name' is not defined
我正在尝试做的事情的例子。
class abc():
@staticmethod
def method1():
print('print from method1')
@staticmethod
def method2():
method1()
print('print from method2')
abc.method1()
abc.method2()
Run Code Online (Sandbox Code Playgroud)
输出:
print from method1
Traceback (most recent call last):
File "test.py", line 12, in <module>
abc.method2()
File "test.py", line 8, in method2
method1()
NameError: name 'method1' is not defined
Run Code Online (Sandbox Code Playgroud)
解决这个问题的最佳方法是什么?
我想将代码保留为这种格式,其中有一个类包含这些静态方法并使它们能够相互调用。