Even if I followed the instruction sequences in the README file in the project flaskr, I still couldn't correctly run this application. It's so depressing. I have already seen another similar issue #1902, but it is not helpful.
So what is the error/s you are running into? You should try working through the tutorial (if you haven't already). It explains each step in detail. But I will look into this, it may be my fault that the readme is not in sync on flaskr.
One problem I did run into on master is that the flaskr example is only working with master. This is bc of the fact that the readme specifies using the new FLASK_APP with an app factory pattern. That feature is not supported in the 0.12.2 release. So installing directly from examples/flaskr/ does throw an error.
Aside from waiting for a new release, you could create an wsgi.py file or the like, in the flaskr example to instantiate the application. I suppose the best thing to do is mention both ways in the readme.
Also a lesser issue I ran into is that this: export FLASK_APP=flaskr.factory:create_app()
Should be this: export FLASK_APP="flaskr.factory:create_app()"
Otherwise I get this: syntax error near unexpected token('`
Since this is master, we should add a .flaskenv file instead of exporting vars.
@davidism what do you think should be done about the backwards compatibility in this case? Should we add a wsgi.py? And explain both methods?
I'd rather add a warning to the README:
If you're following the tutorial from a specific version of the docs, be sure to check out the same tag in the repository, otherwise the tutorial may be different than the example.
I have the same problem, but I figure it out.
try this
git clone https://github.com/pallets/flask.git
cd flask/
pip install -e .
cd examples/flaskr/
pip install -e .
export FLASK_APP="flaskr.factory:create_app()"
flask initdb
flask run
what the README missing is
pip install -e . need to be done in flask and flaskr, two dirsexport statement need double quoteThis is what I get when I attempt the second 'pip install -e . ' --> Command "python setup.py egg_info" failed with error code 1 in /Users/thomasoflight/LL_SOFT/PYTHON/FLASK_GIT/flask/examples/flaskr/
I just want to reinforce what @davidism said: you need to checkout the correct version of the example. Clone the repo, then do git checkout 0.12.2 That is the most current version which is documented. If that should change in the future just look at the URL of the documentation what version is current and then checkout that version.
Even with the versions matching, there's some subtle differences. https://github.com/pallets/flask/blob/f347d3c59e3304474ca85b17e24261f127b27282/examples/flaskr/flaskr/flaskr.py#L20 (from 0.12 branch) to: https://web.archive.org/web/20170705130806/http://flask.pocoo.org/docs/0.12/tutorial/setup/
In particular, this line does not appear in the example code:
app.config.from_object(__name__) # load config from this file , flaskr.py
Does this line make sense? In the context of this example, it doesn't seem like __name__ points to an object. The source code has an example of using this function like app.config.from_object('yourapplication.default_config')
https://github.com/pallets/flask/blob/470112dd6e708a18eb4ec1daa10c4ea276620dbf/flask/config.py#L153
Since the tutorial isn't pulling in code, tested directly, perhaps the recent warning should also note that the there may be subtle differences.
Name is the string representation of the current module. It's loading config from the current file.
But how is it referencing the config from this current file? That file (flaskr.py) doesn't appear to be a config object, as it's actually a script busy creating the app itself. That line suggests somehow recursively figuring out the config.
It would make more sense to me if it was something like app.config.from_object(f'{__name__}.config') similar to the example above. Unfortunately the example doesn't seem to follow this pattern so it's tricky to see how it works in practice.
There are no specific config objects. Flask just looks at upper case variables on whatever object you pass it. Modules are objects.
But in this case, the snippet and the example code show no upper case variables, so it's not clear why you would run app.config.from_object(__name__) in this context (and I've never seen something like that in a flask app, altho I'm not super experienced with flask).
For this line to make sense, it should have a line preceding it defining an actual config variable with a comment explaining that flask will automagically use upper case variables in the passed in object as config variables.
This discussion is all moot, since I'm already rewriting the tutorial and examples.
continued in #2513
Most helpful comment
I have the same problem, but I figure it out.
try this
what the README missing is
pip install -e .need to be done in flask and flaskr, two dirsexportstatement need double quote