2013-04-24 75 views
5

我用Flask在virtualbox上構建了一個網站。該網站可以在本地主機上打開,但無法通過端口轉發打開,因此我將代碼從manage.run()更改爲manage.run(host='0.0.0.0')燒瓶錯誤:typeerror run()得到了一個意外的關鍵字參數'host'

的問題是,我收到此錯誤:發生

typeerror run() got an unexpected keyword argument 'host'. 

類似的錯誤,當變化manage.run()manage.run(debug=True)。我只是遵循Flask文檔。 http://flask.pocoo.org/docs/quickstart/#a-minimal-application任何人都可以讓我知道爲什麼我收到此錯誤?

#!/usr/bin/env python 
#-*- coding:utf-8 -*- 

"""Manage Script.""" 

from sys import stderr, exit 

from flask.ext.script import Manager, prompt_bool 

from szupa import create_app 
from szupa.extensions import db 
from szupa.account.models import User 
from szupa.context import create_category_db 


app = create_app() 
manager = Manager(app) 


@manager.command 
def initdb(): 
    """Initialize database.""" 
    db.create_all() 
    create_category_db() 


@manager.command 
def migrate(created, action="up"): 
    module_name = "migrates.migrate%s" % created 
    try: 
     module = __import__(module_name, fromlist=["migrates"]) 
    except ImportError: 
     print >> stderr, "The migrate script '%s' is not found." % module_name 
     exit(-1) 
    if prompt_bool("Confirm to execute migrate script '%s'" % module_name): 
     try: 
      action = getattr(module, action) 
     except AttributeError: 
      print >> stderr, "The given action '%s' is invalid." % action 
      exit(-1) 
     action(db) 
     print >> stderr, "Finished." 


@manager.command 
def dropdb(): 
    """Drop database.""" 
    if prompt_bool("Confirm to drop all table from database"): 
     db.drop_all() 


@manager.command 
def setadmin(email): 
    """Promote a user to administrator.""" 
    user = User.query.filter_by(email=email).first() 
    if not user: 
     print >> stderr, "The user with email '%s' could not be found." % email 
     exit(-1) 
    else: 
     user.is_admin = True 
     db.session.commit() 


if __name__ == "__main__": 
    manager.run() 
+0

很高興您找到解決方案!你可以發佈一個答案,解釋你如何解決它並鏈接到該頁面。它可以幫助任何遇到同樣問題並遇到此帖子的人。這是一個[工作版本的鏈接](https://web.archive.org/web/20130218044123/http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-flask- mongoengine /)。 – SuperBiasedMan 2015-12-18 12:20:15

回答

1

作爲@ fangwz0577在評論中說,他們用manager.add_command解決了這個問題。他們鏈接的存檔版本是here

Next, create the manage.py file. Use this file to load additional Flask-scripts in the future. Flask-scripts provides a development server and shell:

from flask.ext.script import Manager, Server 
from tumblelog import app 

manager = Manager(app) 

# Turn on debugger by default and reloader 
manager.add_command("runserver", Server(
    use_debugger = True, 
    use_reloader = True, 
    host = '0.0.0.0')) 
+1

我沒有通知燒瓶,所以如果有人想寫一個更好的答案,請做。我只是發佈此引用相關部分,並使用工作鏈接來保存來自@ fangwz0577評論的信息。 – SuperBiasedMan 2015-12-18 12:27:06

相關問題