Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask confusion with app

Tags:

python

flask

I am starting a flask project, and in my code I have

from flask import Flask, render_template, abort app = Flask(__name__) 

Now what exactly is app?

I am following this guide and I am particularly confused about the structure because he has chosen to have directory named app/ and is his app/__init__.py he has

from flask import Flask app = Flask(__name__) from app import views 

and in his app/views.py he has

from app import app 

What the hell is it with all these app's?!

like image 465
kasperhj Avatar asked Jan 23 '13 18:01

kasperhj


1 Answers

I think the main confusion is in the line:

from app import app 

You have a python package (a folder with __init__.py file) named "app". From this folder, you are now importing the variable "app" that you defined below in __init__.py file:

app = Flask(__name__) 

Rename the folder from app to say "myproject". Then you will call

from myproject import app 

Also, you will import views as

from myproject import views 
like image 95
codegeek Avatar answered Oct 05 '22 11:10

codegeek