我是编码领域的新手。我按照以下链接中的说明构建了Web应用程序,该应用程序可以在本地计算机上正常运行。
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
将其部署到远程服务器后,我收到500错误。错误日志显示:
[Tue Oct 09 02:42:27.517360 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] mod_wsgi (pid=6257): Target WSGI script '/var/www/PersonalApp/personalapp.wsgi' cannot be loaded as Python module.
[Tue Oct 09 02:42:27.517374 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] mod_wsgi (pid=6257): Exception occurred processing WSGI script '/var/www/PersonalApp/personalapp.wsgi'.
[Tue Oct 09 02:42:27.517397 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] Traceback (most recent call last):
[Tue Oct 09 02:42:27.517423 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] File "/var/www/PersonalApp/personalapp.wsgi", line 8, in <module>
[Tue Oct 09 02:42:27.517460 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] from PersonalApp import app
[Tue Oct 09 02:42:27.517469 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] File "/var/www/PersonalApp/PersonalApp/__init__.py", line 6, in <module>
[Tue Oct 09 02:42:27.517482 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] from wtforms import Form, StringField, PasswordField, TextAreaField, validators
[Tue Oct 09 02:42:27.517518 2018] [wsgi:error] [pid 6257:tid 140375628965632] [client 99.111.155.184:22844] ImportError: No module named wtforms
项目结构:
|--------PersonalApp
|----------------PersonalApp
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
|----------------personalapp.wsgi
personalapp.wsgi
#! /usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/PersonalApp/")
from PersonalApp import app as application
__ init __。py(部分代码)
from datetime import datetime
from sqlalchemy.sql.functions import now
from flask import Flask, render_template, flash, redirect, url_for, request
from flask_sqlalchemy.model import Model
from flask_sqlalchemy import SQLAlchemy
from wtforms import Form, StringField, TextAreaField, validators
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret_key'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
本地和远程的以下内容相同:
Server version: Apache/2.4.18 (Ubuntu)
Python 2.7.12
server
Package Version
---------------- -------
Click 7.0
Flask 1.0.2
Flask-SQLAlchemy 2.3.2
Flask-WTF 0.14.2
itsdangerous 0.24
Jinja2 2.10
MarkupSafe 1.0
pip 18.1
psycopg2 2.7.5
setuptools 40.4.3
SQLAlchemy 1.2.12
Werkzeug 0.14.1
wheel 0.32.1
WTForms 2.2.1
VERSION="16.04.5 LTS (Xenial Xerus)"
两者之间的唯一区别是:
服务器
Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-1069-aws x86_64)
本地计算机
Linux Lite 3.8 (GNU/Linux 4.4.0-138-generic i686)Linux Lite 3.8 (GNU/Linux 4.4.0-138-generic i686)
我不确定我缺少什么,因为它正在本地计算机上运行。任何指导将不胜感激。预先谢谢你!
答案 0 :(得分:1)
我建议在您的import sys, os; print(sys.version); print(sys.executable);
的第一行添加一个init.py
,以检查您的mod_wsgi使用哪个python解释器。如果不同,则应为mod_wsgi的python解释器安装软件包,或指定已安装所有软件包的所需解释器的路径(不确定在DO中是否可行)。
答案 1 :(得分:0)
我更新了项目结构,现在可以在遥控器上使用了。我没有更改本地计算机上的原始结构,该结构仍然有效。有趣。也许我忽略了一些小细节。再次感谢您尝试帮助我解决问题。
yourapp/
config.py
__init__.py
views.py
models.py
forms.py
static/