How can I convert my python program into a web app on PythonAnywhere?

耗尽温柔 提交于 2020-08-09 13:57:12

问题


I have made a python program. Out of curiosity, I want to implement it on a website so that my friends can run it without seeing the code.
Here's the Github link of my program code: .py file, .ipynb file.
I have opened a free account on PythonAnywhere and added a new web app with the Flask framework. It has a default file flask_app.py:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello from Flask!'

I have uploaded my .py file too. Having no experience with Python web apps, I've looked at the articles about Flask. Seems I need to translate my python code into some different structure. But I can't figure out how to connect and modify my .py file to the flask structure.

Can you kindly check my codes in Github and help me to implement it in the Flask framework?

Or is there any easy way else such that I just need to paste my python program into a file and it will be automatically implemented as a web app?


回答1:


There's quite a lot of work involved in turning an interactive script like that int a website, but it is possible. This tutorial on the PythonAnywhere blog has a step-by-step guide that works up to a website that takes a series of inputs across multiple pages, and produces an output, so it might be a good starting point.




回答2:


You can't just put this code into your flask api. There needs to be client rendering as well. What you are looking for is a .io type web game. Have a look at https://victorzhou.com/blog/build-an-io-game-part-1/ This article details the steps required for a browser based game.



来源:https://stackoverflow.com/questions/63095658/how-can-i-convert-my-python-program-into-a-web-app-on-pythonanywhere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!