Saturday, 15 January 2011

python - CherryPy website design -


I'm trying to refer to my website code more elegant.

My current code is set up like this:

  square root (object): def __init __ (self): ... def need_token (token, REDIR): Token if = cherrypy.session ["token"]: self.redirect (REDIR, "bad token") def require_logged_in (REDIR): if not self.logged_in (): self.redirect ("Redire," should be logged in " ) @ Cherrypy.exposedef index (self): ... @ Cherrypy.expose DEF login (auto, user name, password, return_to): self.login_user (username, password) self.redirect (fix_url (return_to)) @ cherrypy.expose def logout (auto, token, return_to): self . Need_token (token, fix_url (return_to)) self.logout_user () self.redirect (fix_url (return_to)) @ cherrypy.expose DEF member_area_query (auto, query): self.require_logged_in ("/") not self.test_query (query if ): Self.redirect (current_page, "question failed.") ... ...   

There is a big annoyance about which page I would have manually passed I I want to redirect.

  • If this member is the page area and the user is no longer signing in, then I want to enter "/"
  • Otherwise, the redirects should go to the same page that was requested (on which I show an error message)

    So my question is:

    • I'm better Page
    • Is anything that CherryPy built in can help me?
    • ? Can I define how can I use decorators to redirect the default page to be redirected? Or to call need_ * function?
    • Can any Cheripaw Tool help?

      They are not logged in, they can just do something like this Is:

        def not_logged_in (): self.redirect ('' 'must be logged in' ')   

      I myself am about cherry I can not speak in, but I think all your codes need to break some functions.

No comments:

Post a Comment