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)




sábado, 18 de septiembre de 2021

upload your app to githup

open a browser:

 -create account in github

-login

-click on plus button top-right "new repository"

set a name for the repository for example "tablas2"

check "public"

and Add a Readme File

click "create repository"

That's it.


open a Terminal:

git clone https://github.com/[user-name]/[repo].git

cd repo

-work here your files, dont forget create a .gitignore file

https://www.toptal.com/developers/gitignore with the terms linux, flask, venv

-at the end

git add .

git commit -m "my first commit"

git remote add origin https://[token]@github.com/[username]/[repo]

git push --set-upstream origin master (after that, only use "git push")

miércoles, 8 de septiembre de 2021

how configure flask dev server to be visible across your local network

write and execute this on console:

flask run --hots=0.0.0.0

then you can access to your app on browser normally but

to access in your cellphone 

you must type the url that appears in console after execute the previous command


* Serving Flask app 'run.py' (lazy loading)

 * Environment: development

 * Debug mode: on

 * Running on all addresses.

   WARNING: This is a development server. Do not use it in a production deployment.

 * Running on http://192.168.0.125:5000/ (Press CTRL+C to quit)

 * Restarting with stat

 * Debugger is active!

 * Debugger PIN: 144-786-933