1

flask-mega-tutorial and I found some error when I execute my code. first I have init.py

from flask import Flask

app = Flask(__name__)

from app import routes

then routes.py

from app import app

@app.route('/')
@app.route('/index')
def index():
    return "Hello, World!"

And last I have microblog.py to execute my code

from app import app

app.run(debug=True)

but when I execute FLASK_APP = microblog.py then flask run, I found this

  • Serving Flask app "microblog.py"
  • Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
  • Debug mode: off Usage: flask run [OPTIONS]

Error: While importing "microblog", an ImportError was raised:

Traceback (most recent call last): File "e:\skripsiku\flask\lib\site-packages\flask\cli.py", line 235, in locate_app import(module_name) File "E:\skripsiku\microblog.py", line 1, in from app import app ImportError: cannot import name 'app'

Oh and lastly there is my folder structure. I have main folder named skripsiku then in there I have app folder (in : init.py, routes.py) and microblog.py. Can anyone help me? thank you

4
  • 1
    So how is the folder structure? It is a bit tiresome to research the folder structure of the flask mega tutorial in order to answer your question. Commented Jul 3, 2018 at 7:37
  • I have main folder named skripsiku then in there I have app folder (in : init.py, routes.py) and microblog.py Commented Jul 3, 2018 at 7:50
  • You should edit your question and put that there in a readable form. Questions are harder to answer if the reader has to pick all the information from the comments. Commented Jul 3, 2018 at 7:53
  • misnaming your package init file as init.py or using only a single underscore either side will cause this error. It should be named __init__.py (note the two underscores before and after init) Commented Oct 12, 2018 at 6:25

2 Answers 2

0

try this:

from app import app as appl

you can use any name in place of appl

Sign up to request clarification or add additional context in comments.

2 Comments

I tried that but same error was occured, from app import app as appl ImportError: cannot import name 'app'
0

The directory for that tutorial is

enter image description here

minus the pycache and .vscode.

According to the tutorial, FLASK_APP=fua.py or microblog.py in your case. I am assuming that you did flask run in the C:\xampp\htdocs\FUA App\app> directory since I faced a similar error when running that command from that directory.

I solved the problem by running the command from the C:\xampp\htdocs\FUA App.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.