2015-12-27 9 views
5

Konfigurieren Sie Gunicorn, um eine Flaschenanwendung zu finden. Ich denke, Anwendungsname ist innerhalb create_function() definiert verbirgt die Anwendung von run.py; Ich weiß jedoch nicht, wie ich das beheben soll. Hier ist der Fehler, wenn sie mit der Anwendung auszuführen gunicorn:Wie setze ich Gunicorn, um eine Flaschenapplikation zu finden?

1 (venv) MacPro:11a toshio$ gunicorn run:app 
    2 [2015-12-27 15:10:45 +0900] [83437] [INFO] Starting gunicorn 19.4.1 
    3 [2015-12-27 15:10:45 +0900] [83437] [INFO] Listening at: http://127.0.0.1:8000 (83437) 
    4 [2015-12-27 15:10:45 +0900] [83437] [INFO] Using worker: sync 
    5 [2015-12-27 15:10:45 +0900] [83440] [INFO] Booting worker with pid: 83440 
    6 Failed to find application: 'run' 
    7 [2015-12-27 15:10:51 +0900] [83440] [INFO] Worker exiting (pid: 83440) 
    8 [2015-12-27 15:10:52 +0900] [83437] [INFO] Shutting down: Master 
    9 [2015-12-27 15:10:52 +0900] [83437] [INFO] Reason: App failed to load. 
10 (venv) MacPro:11a toshio$ 

der Anwendungsstruktur folgt:

1 ├── app 
    2 │   ├── __init__.py 
    3 │   ├── main 
    4 │   │   ├── __init__.py 
    5 │   │   ├── forms.py 
    6 │   │   └── routes.py 
    7 │   ├── models.py 
    8 │   ├── static 
    9 │   │   ├── js 
10 │   │   ├── css 
11 │   │   ├── pdf 
12 │   └── templates 
13 │    ├── base.html 
14 │    ├── index.html 
15 │    ├── login.html 
16 ├── config 
17 │   └── development.py 
18 ├── data-dev.sqlite3 
19 ├── run.py 

Das Paket constructer app/__ init__.py Code:

1 import os 
    2 import subprocess 
    3 import imghdr 
    4 from datetime import datetime 
    5 from flask import Flask, render_template, session, g, redirect, url_for, request 
    6 from flask.ext.script import Manager 
    7 from flask.ext.wtf import Form 
    8 from flask.ext.bootstrap import Bootstrap 
    9 from wtforms import StringField, SubmitField, ValidationError, PasswordField, BooleanField 
10 from wtforms.validators import Required, Length 
11 from werkzeug import secure_filename 
12 from werkzeug.security import generate_password_hash, check_password_hash 
13 from flask_wtf.file import FileField 
14 from flask.ext.sqlalchemy import SQLAlchemy 
15 from flask.ext.migrate import Migrate, MigrateCommand 
16 from flask.ext.login import LoginManager, UserMixin, login_user, logout_user, login_required 

18 bootstrap = Bootstrap() 
19 db = SQLAlchemy() 
20 lm = LoginManager() 
21 lm.login_view = 'main.login' 
22 
23 def create_app(config_name): 
24  """ Create an application instance """ 
25  app = Flask(__name__, static_folder = 'static') 
26 
27  # import configration 
28  cfg = os.path.join(os.getcwd(), 'config', config_name + '.py') 
29  app.config.from_pyfile(cfg) 
30 
31  # initialize extenstions 
32  bootstrap.init_app(app) 
33  db.init_app(app) 
34  lm.init_app(app) 
35 
36  # import blueprints 
37  from .main import main as main_blueprint 
38  app.register_blueprint(main_blueprint) 
39 
40  return app 

Zuletzt run.py ist folgende:

1 #!/usr/bin/env python 
    2 from app import create_app, db 
    3 from app.models import User, Book 
    4 
    5 
    6 if __name__ == '__main__': 
    7  app = create_app('development') 
    8  with app.app_context(): 
    9   db.create_all() 
10   if User.query.filter_by(username='somebody').first() is None: 
11    User.register('somebody', 'abc') 
12  app.run() 
+0

'gunicorn app : run' könnte auch funktionieren. – wgwz

Antwort

4

Try gunicorn von der Kommandozeile wie folgt auszuführen:

gunicorn 'app:create_app("development")' 
+1

Was für eine schnelle Antwort! Es funktioniert, fantastisch !!! Fügen Sie den Rest des Codes in run.py hinzu. sagen wir, setzen db.create_all() in create_app()? –

1

wsgi.py Datei zu Ihrem Projekt hinzufügen und folgenden Zeilen, um es hinzuzufügen:

from app import create_app 

application = create_app('development') 
if __name__ == "__main__": 
    application.run() 

Speichern und schließen Sie Ihre neue Datei , gehen Sie zu Ihrem App-Ordner und führen Sie:

gunicorn --bind 0.0.0.0:8000 wsgi 
+0

Danke, aber es scheint, dass es nicht funktioniert. Ich habe den gleichen Fehler wie folgt: '(venv) MacPro: 11a toshio $ gunicorn --bind 0.0.0.0:8000 wsgi [2015-12-27 17:23:58 +0900] [84005] [INFO] Start Gunicorn 19.4.1 [2015-12-27 17:23:58 +0900] [84005] [INFO] Abhören unter: http://0.0.0.0:8000 (84005) [2015-12-27 17: 23:58 +0900] [84005] [INFO] Verwenden von Worker: sync [2015-12-27 17:23:59 +0900] [84008] [INFO] Starten von Worker mit Pid: 84008 Fehler beim Suchen der Anwendung: ' wsgi '' –

+0

@ Toshio Führen Sie es aus Ihrem Projektordner? Beachten Sie auch, dass wsgi.py in Ihrem Projektordner platziert werden sollte. –

+0

Ja, das tue ich. In meinem Projektordner Ich habe diese: 'Dockerfile App doc_data.txt run-flask.py unicorn_key.pem README Config gunicorn.err run.py wsgi.py __pycache__ Daten dev.sqlite3 requirements.txt tree.log ' @ Toshio –

Verwandte Themen