I built a website on virtualbox with Flask. The website can be opened on localhost, but I cannot open it through Port forwarding, so I changed the code from manage.run()
to manage.run(host='0.0.0.0')
.
The problem is that I am receiving this error:
typeerror run() got an unexpected keyword argument 'host'.
The similar error occurs when change manage.run()
to manage.run(debug=True)
. I just followed the Flask documentation.http://flask.pocoo.org/docs/quickstart/#a-minimal-application Could anyone let me know why I'm receiving this error?
#!/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()
As @fangwz0577 said in a comment, they solved the problem using manager.add_command
. The archived version of their link is 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') )
The answer of @SuperBiasedMan is the one who worked for me, except that the import from flask.ext.script import Manager, Server
doesn't work
because it was deprecated (as an issue on flask's github shows: https://github.com/pallets/flask/issues/1135#issuecomment-61860862)
So if you are still struggling, try to use from flask_script import Manager, Server
instead.
Also, on Linux the creation of a "bare bones" application is not needed, just create the __init__.py
file and make the manage.py
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With