我遵循Mastering Flask教程书和this DO tutorial部署到Digital Ocean,并且已经脱轨。我希望wsgi.py可以很简单,但我已尽力了。这是我的文件结构:
~/
├── flaskblog
│ ├── flaskblogenv
│ ├── __init__.py
│ ├── manage.py
│ ├── migrations
│ ├── requirements.txt
│ └── webapp
│ ├── config.py
│ ├── controllers
│ ├── extensions.py
│ ├── forms.py
│ ├── __init__.py
│ ├── models.py
│ ├── static
│ └── templates
└── wsgi.py
以下是另一个教程中的wsgi.py内容:
from flaskblog import webapp as application
if __name__ == "__main__":
application.run()
当我跑步时:
uwsgi --socket 0.0.0.0:8000 -H ~/flaskblog/flaskblogenv --protocol=http -w wsgi
这是我得到的:
(flaskblogenv) root@flask-blog:~# uwsgi --socket 0.0.0.0:8000 -H ~/flaskblog/flaskblogenv --protocol=http -w wsgi.py
*** Starting uWSGI 2.0.12 (64bit) on [Sat May 7 03:35:30 2016] ***compiled with version: 4.8.4 on 05 May 2016 20:15:54
os: Linux-3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016
nodename: flask-blog
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root
detected binary path: /root/flaskblog/flaskblogenv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3750
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:8000 fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Set PythonHome to /root/flaskblog/flaskblogenv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x94bce0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./wsgi.py", line 1, in <module>
from flaskblog import webapp as application
File "./flaskblog/webapp/__init__.py", line 5, in <module>
from .models import db, mongo, User, Role, Post, Comment, Tag
File "./flaskblog/webapp/models.py", line 13, in <module>
from webapp.extensions import bcrypt
ImportError: No module named webapp.extensions
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 23544, cores: 1)
这是models.py的顶部:
import datetime
from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer,
BadSignature,
SignatureExpired
)
from flask import current_app
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import AnonymousUserMixin
from flask.ext.mongoengine import MongoEngine
from webapp.extensions import bcrypt
编辑添加教程链接。
答案 0 :(得分:1)
您是否尝试过from flaskblogenv.webapp.extensions import bcrypt
?
答案 1 :(得分:0)
由于app工厂,我不得不以不同的方式调用uwsgi。这实际上出现在我关注的那本书中:
uwsgi --socket 0.0.0.0:5000 -H ~/flaskblog/flaskblogenv --protocol=http
--module 'create_app('project.config.ProdConfig')'