Python Flask-在Ubuntu上部署时入口点和应用程序结构存在问题

时间:2019-02-04 14:25:16

标签: python flask

我正在开发一个烧瓶应用程序,可以在本地计算机上工作,但是当我尝试将其部署到Digital ocean ubuntu时,入口点和应用程序结构出现了问题。

locate_app中的文件“ /home/ubuntu/.local/lib/python2.7/site-packages/flask/cli.py”,第246行     '无法导入“ {name}”。'。format(name = module_name) NoAppException:无法导入“ webapp”。

应用程序结构:

首页>> ubuntu >>

>>s_chaser

        |-- FlaskApp
        |   |-- FlaskApp
        |   |   |-- __pycache__
        |   |   |-- app
        |   |   |   |-- __pycache__
        |   |   |   |-- static
        |   |   |   |-- templates
                |   |-- __init__.py
                |   |-- errors.py
                |   |-- forms.py
                |   |-- routes.py
                |   |-- models.py
                |                    
                |-- __init__.py
                |-- config.py
                |-- scdb1_local.db
        |   |   |-- logs
        |   |   |-- migrations
        |   |   |-- scripts
        |   |   |-- static
        |   |   |-- s_venv
                |-- s_chaser.py

FlaskApp / s_chaser.py

from app.models import User, Blogpost


@app.shell_context_processor
def make_shell_context():
    return {'db': db, 'User': User, 'Blogpost': Blogpost} 



FlaskApp / config.py

import os
from dotenv import load_dotenv


basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(basedir, '.env'))

class Config(object):
    # ...
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'

    SQLALCHEMY_DATABASE_URI = os.environ.get('mysql://root:<password>@localhost/scdb1') or \
        'sqlite:///' + os.path.join(basedir, 'scdb1_local.db')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    MAIL_SERVER = os.environ.get('MAIL_SERVER')
    MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25)
    MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    ADMINS = ['mygmail@gmail.com']

FlaskApp / app / 初始化 .py

from flask import Flask
from config import Config, basedir
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_sqlalchemy_session import flask_scoped_session
from flask_login import LoginManager
from sqlalchemy.orm import sessionmaker, Query
from sqlalchemy import create_engine, func
import logging
from logging.handlers import SMTPHandler, RotatingFileHandler
import sys
import os


app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'

engine = create_engine(os.environ.get('mysql://root:<password>@localhost/scdb1') or \
        'sqlite:///' + os.path.join(basedir, 'scdb1_local.db'))

session_factory = sessionmaker(bind=engine)
session = flask_scoped_session(session_factory, app)

from app import routes, models, errors

我正在尝试设置入口点: 回声“ export FLASK_APP = s_chaser.py” >>〜/ .profile

我将注销并重新登录,当我运行烧瓶时,我得到:

File "/home/ubuntu/.local/lib/python2.7/site-packages/flask/cli.py", line 246, in locate_app
    'Could not import "{name}".'.format(name=module_name)
NoAppException: Could not import "s_chaser". 

当我设置s-chaser.py的完整路径并尝试运行flask时,我会得到这个

$ export FLASK_APP = s_chaser / FlaskApp / FlaskApp / s_chaser.py

$烧瓶

File "/home/ubuntu/surfchaser/FlaskApp/FlaskApp/app/__init__.py", line 2, in <module>
    from config import Config, basedir
ImportError: No module named config

0 个答案:

没有答案