My app has the following layout:
/wsgi/myapp/__init__.py
/wsgi/application
/app.py
File _ init _ .py:
from flask import Flask #python flask framework!
def create_app(app_name=None):
app_name = app_name or __name__
app = Flask(app_name)
return app
File application (without .py extension!):
from myapp import create_app
application = create_app('myapp')
@application.route('/', methods=['GET', 'POST'])
def index():
return 'My OpenShift Flask app'
File app.py has the following line which causes error:
import imp
app = imp.load_source('application', 'wsgi/application')
The error is "No module named myapp". What else I need to solve the issue?
add the import path
import sys
sys.path.append('wsgi')
import imp
app = imp.load_source('application', 'wsgi/application')
Does it work?
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'application.py')
application = wsgi.application
this should work in python 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.