使用pythonanywhere在Web上部署Python Flask应用 [英] Deploying Python Flask app on web using pythonanywhere

查看:60
本文介绍了使用pythonanywhere在Web上部署Python Flask应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用pythonanywhere公开部署我的flask应用程序.我完全遵循了所有步骤.尝试使用virtualenv和不使用virtualenv来实现它,但没有效果.

I want to deploy my flask app publicly using pythonanywhere. I have followed all steps exactly. Tried implementing it with virtualenv and without virtualenv but none works.

我可以使简单的烧瓶页面"Hello to flask app"正常工作,但是我的代码无法正常工作.

I can get the simple flask page 'Hello to flask app" working but my code is not working.

路径为/home/anwaraliafshan/bella,文件为afshan.py

Path is /home/anwaraliafshan/bella and file is afshan.py

这是我的WSGI.py,我尝试用bella和afshan替换flask,但是没有任何效果.虽然在python3上成功安装了imutil,但也在error.log中获得了导入imutil错误.请帮助我找到原因.预先感谢

This is my WSGI.py and I tried replacing flask with bella and afshan but nothing worked. Also getting import imutil error in error.log though install imutil successfully on python3 Please help me finding the cause. Thanks in advance

# This file contains the WSGI configuration required to serve up your
# web application at http://<your-username>.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Flask project

import sys

# add your project directory to the sys.path
project_home = '/home/anwaraliafshan/bella/'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from flask import app as application  # noqa

推荐答案

引自其网站:

import sys
path = '/home/yourusername/mysite'
if path not in sys.path:
   sys.path.insert(0, path)

from flask_app import app as application

这篇关于使用pythonanywhere在Web上部署Python Flask应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆