2013-04-24 30 views
5

Tôi đã xây dựng một trang web trên VirtualBox với Flask. Trang web có thể được mở trên localhost, nhưng tôi không thể mở nó thông qua cổng chuyển tiếp, vì vậy tôi đã thay đổi mã từ manage.run() thành manage.run(host='0.0.0.0').Lỗi Flask: typeerror run() nhận được một đối số từ khoá không mong muốn 'host'

Vấn đề là tôi nhận được lỗi này:

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

Các lỗi tương tự xảy ra khi thay đổi manage.run()-manage.run(debug=True). Tôi chỉ cần làm theo các tài liệu Flask. http://flask.pocoo.org/docs/quickstart/#a-minimal-application Có ai cho tôi biết lý do tôi nhận được lỗi này không?

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

Rất vui khi bạn tìm thấy giải pháp! Bạn có thể đăng câu trả lời giải thích cách bạn giải quyết và liên kết đến trang đó. Nó sẽ giúp bất cứ ai khác có cùng một vấn đề và đi qua bài đăng này. Đây là [phiên bản hoạt động của liên kết] (https://web.archive.org/web/20130218044123/http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-flask- mongoengine /). – SuperBiasedMan

Trả lời

1

Như @ fangwz0577 nói trong một chú thích, họ đã giải quyết được vấn đề sử dụng manager.add_command. Phiên bản lưu trữ của liên kết của họ là 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

Tôi không được thông báo về bình, vì vậy nếu ai đó muốn viết một câu trả lời tốt hơn, xin vui lòng. Tôi chỉ đăng bài này để trích dẫn phần có liên quan và sử dụng một liên kết làm việc để bảo toàn thông tin từ nhận xét của @ fangwz0577. – SuperBiasedMan

Các vấn đề liên quan