Initial setup of Flask Mega Tutorial on pythonanywhere

Upon successful completion of the pythonanywhere flask tutorial (pa.com) Miguel Greenberg " Flask Mega Tutorial " (fmt) beckoned. Unfortunately, I did not even get to "Hello, World". Here is what I did:

At pa.com, trying to follow fmt verbatim is not:

python3 -m venv flask

leads to an error

ensurepip is not available

and we do not have access to sudo.

Ignoring it, I reasoned that all Miguel was asking for was to distribute the functionality that we see in one file in the pa.com tutorial (flask_app.py) into several files that would make it easier to create a complete application. Since pa.com is already setting up my core jar web application and python 3.4 without being able to configure virtual env. it seemed not to be a block, at least not at first.

The fmt in the base directory pa.com (pwd β†’ home / {username } / microblog) - where the file is located flask_app.py, which successfully creates a page pa.com guide, I set directories appand tmpand create files app/__init__.py, app/views.pyand run.pyat the direction of fmt

Clicking on the application page (run.py is the only file in the main directory) throws an Unhandled exception on the page.

flask_app.py(, -, , pa.com ) .

flask_app.py :

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
  return "working from flask_app.py"

, run.py Unhandled Exception.

:

from app import app run.py views.py
from app import views __init__.py

... ""? , , , , . - ? pa.com /.

, - , , .

+4
1

: app.run() PythonAnywhere - , run.py. , PA . , wsgi.

app, app/__init__.py ( , app, ! )

, , , sys.path. "" application :

# assuming we have /home/myusername/microblog/app/__init__.py:
path = '/home/myusername/microblog'
if path not in sys.path:
    sys.path.append(path)

# now we can import the app variable from the app folder __init__
# and rename it to application
from app import app as application

: a pythonanywhere guide sys.path pythonanywhere wsgi

+5

Source: https://habr.com/ru/post/1624727/


All Articles