2011-09-23 276 views
1

我在理解如何將龍捲風應用程序分發到多個文件中遇到了一些麻煩。我需要一個文件創建應用程序實例,另一個文件處理登錄/註銷功能,另一個處理配置文件頁面視圖等等。但我沒有得到的是如何做到這一點。 可以說,比如我有兩個文件: -app.py(創建應用程序實例) -auth.py(登錄/註銷功能)在Python中導入模塊

app.py 
>import tornado 
>import auth 
> handlers = [ 
      (r"/", MainHandler), 
      (r"/auth", auth.AuthHandler), 
      (r"/logout", auth.LogoutHandler), 
     ] 

這工作得很好,但是當我有app.py因爲這:

>import tornado 
>import auth 
>import profile 
> handlers = [ 
      (r"/", MainHandler), 
      (r"/auth", auth.AuthHandler), 
      (r"/logout", auth.LogoutHandler), 
      (r"/profile", profile.ViewHandler), 
     ] 

auth.py 
>import tornado 
>import app 
>class AuthHandler(app.BaseHandler) 
> > ... 
>class LogoutHandler(app.BaseHandler) 
> >... 

and in profile.py i have this: 
>import app 
>import tornado 
>class ViewProfile(app.BaseHandler) 
---it shows error that in profile.py module app has no attribute BaseHandler 

回答

1

如果在auth.py和profile.py中刪除「導入應用程序」,會發生什麼情況?看來你正在創造循環進口。

+0

它顯示名稱的應用程序沒有被定義爲app.BaseHandler是基類,現在的應用程序沒有導入的錯誤。即使我想這樣,但不能得到一個解決方案 – tushar

+0

嗯,我認爲你應該重組你的文件以避免這些循環引用。也許你可以把Basehandler放在另一個文件(base.py)中,然後從auth.py和profile.py指向它 – RickyA