2013-04-24 15 views
5

Ho costruito un sito Web su virtualbox con Flask. Il sito Web può essere aperto su localhost, ma non riesco ad aprirlo tramite il port forwarding, quindi ho cambiato il codice da manage.run() a manage.run(host='0.0.0.0').Flask: typeerror run() ha ottenuto un argomento di parole chiave imprevisto 'host'

Il problema è che sto ricevendo questo errore:

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

L'errore simile si verifica quando il cambiamento manage.run()-manage.run(debug=True). Ho appena seguito la documentazione di Flask. http://flask.pocoo.org/docs/quickstart/#a-minimal-application Qualcuno potrebbe farmi sapere perché sto ricevendo questo errore?

#!/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

Felice di aver trovato una soluzione! Puoi pubblicare una risposta spiegando come hai risolto il problema e il link a quella pagina. Sarebbe utile a chiunque altro abbia lo stesso problema e si imbatta in questo post. Ecco una [versione funzionante del collegamento] (https://web.archive.org/web/20130218044123/http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-flask- mongoengine /). – SuperBiasedMan

risposta

1

Come @ fangwz0577 detto in un commento, hanno risolto il problema utilizzando manager.add_command. La versione archiviata del loro collegamento è 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

Non sono informato della fiaschetta, quindi se qualcuno vuole scrivere una risposta migliore, per favore fallo. Sto solo postando questo per citare la sezione pertinente e utilizzare un link funzionante per preservare le informazioni dal commento di @ fangwz0577. – SuperBiasedMan

Problemi correlati