开发者

importing modules in python

开发者 https://www.devze.com 2023-04-07 07:19 出处:网络
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/lo

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

精彩评论

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

关注公众号