开发者

importing modules in python

i am having some trouble in understanding how to distribute a tornado application into multiple files.i need to have one file which creates the application instance another file which handles login/logout functionality ,another which handles profile page view and so on.but what i dont get is how to do this . lets say for example i have two files: -app.py(creating app instance) -auth.py(login/logout functionality)

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

this works fine but when i have app.py as this:

>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


What happens if you drop the "import app" in both auth.py and profile.py? it seems you are creating circular imports.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜