jueves, 23 de septiembre de 2021

deploy flask app into pythoneverywhere server

 -create an account into www.pythonanywhere.com

-click on the Web menu

-click on the "add a new web app" button.

-select Flask

-select last python version

The route of your app will be something like that: /home/your_user/mysite/flask_app.py

you can change it but you will do it later

-click finish


if you open a browser with the url http://your-user-account.pythoneverywhere.com

it'll show you 

"hello from flask"

-------------------------------

-click on the Console menu

-click on the Bash link

-clone your app from github

-go into the folder of your app and install your libraries like thar:

pip install -r requirements.txt

(previously you had to generate the requirements.txt file like that:

pip freeze>requirements.txt

----------------------

-go to Web Menu

-inthe Code section edit

source code : /home/your-user-account/your-app

and click/ on WSGI configuration file: /var/www/your-user-account_pythonanywhere_com_wsfi.py

edit:

# add your project directory to the sys.path

project_home = '/home/your-user-account/your-app'

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 app import app as application 

[

note:

the first "app" is the name of your main file ( e.g app.py or run.py)

the second "app" is the name of the variable inside your main file

app = Flask(__name__)

]

click on the Save Button

----------------------

-Click on to The Web menu

-click on the reload button

-refresh your browser and that's it!

note: you can force https on your URL, clicking on the Force HTTPS option. (after that, you must click on the reload button)




No hay comentarios:

Publicar un comentario