繁体   English   中英

Flask + uWSGI + nginx:ImportError:没有名为webapp.extensions的模块

[英]Flask+uWSGI+nginx: ImportError: No module named webapp.extensions

我遵循了Mastering Flask教程书和此DO教程(关于如何部署到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

编辑以添加指向教程的链接。

您是否尝试过from flaskblogenv.webapp.extensions import bcrypt

由于应用程序工厂的原因,我不得不以不同的方式调用uwsgi。 这实际上是在我关注的书中:

uwsgi --socket 0.0.0.0:5000 -H ~/flaskblog/flaskblogenv  --protocol=http 
--module 'create_app('project.config.ProdConfig')'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM