2017-01-08 9 views
-1

私はトルネードとウェブサービスの開発には新しく、現在トルネードモジュールを実践するための小さなウェブを実装しています。Tornado rediretが発生しましたTypeError:initialize()missing 1必要な位置引数: 'url'

これは私が私のサーバー用に

import bcrypt 
import concurrent.futures 
#import MySQLdb 
#import markdown 
import os.path 
import re 
import subprocess 
#import torndb 
import tornado.escape 
from tornado import gen 
import tornado.httpserver 
import tornado.ioloop 
import tornado.options 
import tornado.web 
import unicodedata 
from tornado.options import define, options 

define("port",default=8889,help='run on the given port',type=int) 


class HomeHandler(tornado.web.RequestHandler): 

    def get(self): 
     #login here 
     self.render('index.html') 

    def post(self): 
     def readcodebook(codebook): 
      with open(codebook,'r+') as f: 
       CodeLines=f.read().split('\n') 
       combinations={} 
       for c in CodeLines: 
        if len(c)>0: 
         combinations[c.split('\t')[0]]=c.split('\t')[1] 
      return combinations 
     UserFile='/home/john/PyServer/Users/codebook.txt' 
     CodeBook=readcodebook(UserFile) 

     if self.get_argument("login") in CodeBook.keys(): 
      if CodeBook[self.get_argument("login")]==self.get_argument("password"): 
       #correct pwd 
       self.redirect(self.get_argument("next","/display/")) 
      else: 
       #incorrect pwd 
       self.render("index.html", error='incorrect password!') 
       return 
     else: 
      #user not found 
      self.render("index.html", error="account not found!") 
      return 


class DisplayHandler(tornado.web.RedirectHandler): 
    def get(self): 
     self.render("displaycontent.html") 
    pass 


class Application(tornado.web.Application): 
    def __init__(self): 
     handlers = [ 
      (r"/", HomeHandler), 
      (r"/display/", DisplayHandler), 
     ] 
     settings = dict(
      #blog_title=u"Tornado Blog", 
      template_path=os.path.join(os.path.dirname(__file__), "templates"), 
      static_path=os.path.join(os.path.dirname(__file__), "static"), 
      #ui_modules={"Entry": EntryModule}, 
      #xsrf_cookies=True, 
      #cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", 
      #login_url="/auth/login", 
      debug=True, 
     ) 
     tornado.web.Application.__init__(self,handlers,**settings) 

if __name__=="__main__": 
    tornado.options.parse_command_line() 
    http_server=tornado.httpserver.HTTPServer(Application()) 
    http_server.listen(options.port) 
    tornado.ioloop.IOLoop.instance().start() 

を使用Pythonのコードであり、これはユーザーログオン用のindex.htmlです:

CSSFlow 
Login Form 
Previous 
Next 

    Twitter 
    Facebook 
    RSS 
    Newsletter 

<!DOCTYPE html> 
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> 
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]--> 
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]--> 
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]--> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <title>Login Form</title> 
    <link rel="stylesheet" href="css/style.css"> 
    <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--> 
</head> 
<body> 
    <section class="container"> 
    <div class="login"> 
     <h1>Login to Web App</h1> 
     <form method="post" action="/"> 
     <p><input type="text" name="login" value="" placeholder="Username or Email"></p> 
     <p><input type="password" name="password" value="" placeholder="Password"></p> 
     <p class="remember_me"> 
      <label> 
      <input type="checkbox" name="remember_me" id="remember_me"> 
      Remember me on this computer 
      </label> 
     </p> 
     <p class="submit"><input type="submit" name="commit" value="Login"></p> 
     </form> 
    </div> 

    <div class="login-help"> 
     <p>Forgot your password? <a href="index.html">Click here to reset it</a>.</p> 
    </div> 
    </section> 

    <section class="about"> 
    <p class="about-links"> 
     <a href="http://www.cssflow.com/snippets/login-form" target="_parent">View Article</a> 
     <a href="http://www.cssflow.com/snippets/login-form.zip" target="_parent">Download</a> 
    </p> 
    <p class="about-author"> 
     &copy; 2012&ndash;2013 <a href="http://thibaut.me" target="_blank">Thibaut Courouble</a> - 
     <a href="http://www.cssflow.com/mit-license" target="_blank">MIT License</a><br> 
     Original PSD by <a href="http://www.premiumpixels.com/freebies/clean-simple-login-form-psd/" target="_blank">Orman Clark</a> 
    </section> 
</body> 
</html> 

    Live Demo 
    HTML Source 
    SCSS Source 

    Tweet 
    Share 

    View Article 
    Download 
    Download All 

90% Unlimited Downloads Choose from Over 300,000 Vectors, Graphics & Photos.ads via Carbon 

問題は今竜巻がキャッチされない例外がスローされますということです正しいユーザー名とパスワードを使用してindex.htmlのSubmitボタンをクリックすると、Webブラウザにエラー404が見つかりません。

[E 170108 11:21:55 http1connection:54] Uncaught exception 
    Traceback (most recent call last): 
     File "/home/gaobo/anaconda3/lib/python3.5/site-packages/tornado/http1connection.py", line 238, in _read_message 
     delegate.finish() 
     File "/home/gaobo/anaconda3/lib/python3.5/site-packages/tornado/httpserver.py", line 289, in finish 
     self.delegate.finish() 
     File "/home/gaobo/anaconda3/lib/python3.5/site-packages/tornado/web.py", line 2022, in finish 
     self.execute() 
     File "/home/gaobo/anaconda3/lib/python3.5/site-packages/tornado/web.py", line 2042, in execute 
     **self.handler_kwargs) 
     File "/home/gaobo/anaconda3/lib/python3.5/site-packages/tornado/web.py", line 183, in __init__ 
     self.initialize(**kwargs) 
    TypeError: initialize() missing 1 required positional argument: 'url' 

誰もがこの問題を解決する方法を指摘できますか?どうもありがとう!

答えて

0

竜巻にはリダイレクトを達成する2つの方法があります。 1つはRedirectHandlerを使用し、もう1つはRequestHandlerのredirectメソッドを使用します。

上記の例では、これら2つの方法を混在させてエラーが発生します。あなたの例では

、あなたは成功したログインにdisplaycontent.htmlへのリダイレクトを達成するために第二の方法(RequestHandler.redirect)を、使用しているため、あなたがの RequestHandler innsteadするDisplayHandlerの親クラスを交換する必要がありますRedirectHandler

例えば、

class DisplayHandler(tornado.web.RequestHandler): 
    def get(self): 
     self.render("displaycontent.html") 

また、リダイレクト方法のパラメータは、リダイレクトするURL(または別名)でなければなりません。

例えば、

#correct pwd 
self.redirect("/display/") 

リダイレクトの詳細については、linkに従ってください。

+0

ありがとうございます!パラメータがtornado.web.RedirectHandlerからtornado.web.RequestHandlerに変更された場合、私の問題は解決できます! – Buddhainside

関連する問題