sábado, 2 de octubre de 2021

servidor local php slim

desde una terminal situarse dentro de la carpeta del proyecto slim

y ejecutar el sgt comando:


 php -S 0.0.0.0:8888 -t public/


entonces eso habilita a que podamos acceder a nuestra aplicacion a traves de la ip privada de nuestra PC en la red local

para

obtener esa ip desde una terminal ejectar el sgt comando:

hostname -I | awk '{print $1}'

y aparecerá algo similar a 

192.168.0.125

entonces ahora podremos entrar a nuestra app desde cualquier cualquier dispositivo que esté conectado a nuestra red local a través de un browser asi: 

http://192.168.0.125:8888




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


domingo, 8 de agosto de 2021

debug mode

 debug mode let us re starting the server automatically when we make some change.


so, edit env/bin/activate file and add environment variable FLASK_ENV with "development" value


export FLASK_ENV = "development"


jueves, 5 de agosto de 2021

creating first flask app

 create application folder

by console:

mkdir my-first-flask-app

initializate environment

inside the folder ...by console:

virtualenv env

set terminal to listen our environment

source env/bin/activate

then, the word «(env)» will appear at the beginning of the prompt

install flask with his dependencies

pip3 install Flask

at the end of the installing we can list the dependencies installed by:

pip3 freeze

it will show something like this:

click==8.0.1
dataclasses==0.8
Flask==2.0.1
importlib-metadata==4.6.3
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
typing-extensions==3.10.0.0
Werkzeug==2.0.1
zipp==3.5.0

creating our fist Flask app...

create a file called run.py and add this content:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
    return 'Hello, World!'

every Flask application extends from class Flask so we must create 
a instance, in this case, called app with a parameter __name__ which is the name of the module.

route  decorator tell us what function call by url

hello_world() for "/" in this example

the function must return what browser will show
"Hello, World" 

Testing our application

we can use internal server to test our application, but before we must tell it which file it must call at the beginnig setting the environment variable FLASK_APP,

open and edit env/bin/activate file.

add at the end:

export FLASK_APP="run.py"

and save it.

To save this changes, we must going out from our environment

deactivate

and then, activate it again:

source env/bin/activate

now, we can start the internal server, like this:

flask run

 * Serving Flask app 'run.py' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [05/Aug/2021 02:01:35] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [05/Aug/2021 02:01:35] "GET /favicon.ico HTTP/1.1" 404 -

open a browser and go to
http://127.0.0.1:5000

the browser will display

Hello, World!

by default, internal flask server listen to 5000 port
if we want to change it, 
there are 2 ways:
- setting variable FLASK_RUN_PORT
or
writing the port at the end of the executing command, just like this:

flask run --port 6000










martes, 3 de agosto de 2021

installing virtualenv

virtualenv

helps us to isolate our project dependencies creating a virtual environment for every project.

installation:

sudo pip3 install virtualenv

note:

virtualenv needs to be installed with administrative or “Superuser” privileges in order for it to be installed in the right directory and for the command to be recognized


check installation:

which virtualenv 

or

whereis virtualenv

both of them would get the same result:

/usr/local/bin/virtualenv



Installing pip for Python 3

update the package list:

sudo apt update

install pip for python3:

sudo apt install python3-pip

check installation:

pip3 --version

it must response something like this:

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)