librelist archives

« back to archive

problem with the Flaskr example in the documentation

problem with the Flaskr example in the documentation

From:
Tony Wang
Date:
2012-07-11 @ 23:45
I'm following the documentation to learn flask until this page
http://flask.pocoo.org/docs/tutorial/dbinit/ that I have below error in the
python2.7 console:

>>> from flaskr import init_db
> >>> init_db()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "flaskr.py", line 27, in init_db
>     with closing(connect_db()) as db:
>   File "flaskr.py", line 24, in connect_db
>     return sqlite3.connect(app.config['DATABASE'])
> KeyError: 'DATABASE'
>


Can someone tell me how to correct the problem? and why is this problem
occurring? thanks!
-- 
     (\__/)
          (='.'=)
          (")_(")
- 温 良 恭 俭 让 仁 义 礼 智 信
- Through suffering to renown

Re: [flask] problem with the Flaskr example in the documentation

From:
Suhair Hassan
Date:
2012-07-12 @ 04:26
Hi,

Your configuration call should be after the constants declaration step.
for example, app.config.from_object(__name__) should be placed after 
declaring the constants like follows

DATABASE = 'tmp\\flaskr.db'
DEBUG = True
SECRET_KEY = 'development_key'
USERNAME = 'admin'
PASSWORD = 'default'

app.config.from_object(__name__)

hope this helps

On 7/12/2012 5:15 AM, Tony Wang wrote:
> I'm following the documentation to learn flask until this page 
> http://flask.pocoo.org/docs/tutorial/dbinit/ that I have below error 
> in the python2.7 console:
>
>     >>> from flaskr import init_db
>     >>> init_db()
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>       File "flaskr.py", line 27, in init_db
>         with closing(connect_db()) as db:
>       File "flaskr.py", line 24, in connect_db
>         return sqlite3.connect(app.config['DATABASE'])
>     KeyError: 'DATABASE'
>
>
>
> Can someone tell me how to correct the problem? and why is this 
> problem occurring? thanks!
> -- 
> (\__/)
>           (='.'=)
>           (")_(")
> - 温 良 恭 俭 让 仁 义 礼 智 信
> - Through suffering to renown
>

Re: [flask] problem with the Flaskr example in the documentation

From:
Date:
2012-07-12 @ 06:25
Thank you!
I had done it as you say.The answer  can not solve my problem.My flask app
work perfect that it stop working  just in sometimes.

2012/7/12 Suhair Hassan <suhairhassan@ispg.in>

>  Hi,
>
> Your configuration call should be after the constants declaration step.
> for example, app.config.from_object(__name__) should be placed after
> declaring the constants like follows
>
> DATABASE = 'tmp\\flaskr.db'
> DEBUG = True
> SECRET_KEY = 'development_key'
> USERNAME = 'admin'
> PASSWORD = 'default'
>
> app.config.from_object(__name__)
>
> hope this helps
>
> On 7/12/2012 5:15 AM, Tony Wang wrote:
>
> I'm following the documentation to learn flask until this page
> http://flask.pocoo.org/docs/tutorial/dbinit/ that I have below error in
> the python2.7 console:
>
> >>> from flaskr import init_db
>> >>> init_db()
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "flaskr.py", line 27, in init_db
>>     with closing(connect_db()) as db:
>>   File "flaskr.py", line 24, in connect_db
>>     return sqlite3.connect(app.config['DATABASE'])
>> KeyError: 'DATABASE'
>>
>
>
> Can someone tell me how to correct the problem? and why is this problem
> occurring? thanks!
> --
>      (\__/)
>           (='.'=)
>           (")_(")
>  - 温 良 恭 俭 让 仁 义 礼 智 信
> - Through suffering to renown
>
>

Re: [flask] problem with the Flaskr example in the documentation

From:
Gabriel Jordão
Date:
2012-07-12 @ 00:18
In this traceback we can see that the config dict has no key "DATABASE", so
make sure your config has the DATABASE attribute set.


On Wed, Jul 11, 2012 at 8:45 PM, Tony Wang <ivytony@gmail.com> wrote:

> I'm following the documentation to learn flask until this page
> http://flask.pocoo.org/docs/tutorial/dbinit/ that I have below error in
> the python2.7 console:
>
> >>> from flaskr import init_db
>> >>> init_db()
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "flaskr.py", line 27, in init_db
>>     with closing(connect_db()) as db:
>>   File "flaskr.py", line 24, in connect_db
>>     return sqlite3.connect(app.config['DATABASE'])
>> KeyError: 'DATABASE'
>>
>
>
> Can someone tell me how to correct the problem? and why is this problem
> occurring? thanks!
> --
>      (\__/)
>           (='.'=)
>           (")_(")
> - 温 良 恭 俭 让 仁 义 礼 智 信
> - Through suffering to renown
>
>


-- 
*
*
*Gabriel Jordão*

T (71) 3494-3514
C (71) 8780-0519
gabrielpjordao@jusbrasil.com.br
www.jusbrasil.com.br