I recently used flask to develop a website. I cloned a small example from GitHub and used PostgreSQL as the database. When the database service is not opened, the following error is reported ():
Traceback (most recent call last ):
File "/root/workspace_aptana/flask-Bootstrap/APP. py", line 86, in <module>
DB. create_all ()
File "/usr/lib/python2.6/Site-packages/flask_sqlalchemy.py", line 822, in create_all
Self. _ execute_for_all_tables (app, bind, 'create _ all ')
File "/usr/lib/python2.6/Site-packages/flask_sqlalchemy.py", line 814, in _ execute_for_all_tables
OP (BIND = self. get_engine (app, bind), tables = tables)
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/Schema. py", line 2783, in create_all
Tables = tables)
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/engine/base. py", line 1478, in _ run_visitor
With Self. _ optional_conn_ctx_manager (connection) as Conn:
File "/usr/lib64/python2.6/contextlib. py", line 16, in _ enter __
Return self. gen. Next ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/engine/base. py", line 1471, in _ optional_conn_ctx_manager
With Self. contextual_connect () as Conn:
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/engine/base. py", line 1661, in contextual_connect
Self. Pool. Connect (),
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 272, in connect
Return _ connectionfairy (Self). Checkout ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 425, in _ init __
Rec = self. _ connection_record = pool. _ do_get ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 777, in _ do_get
Con = self. _ create_connection ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 225, in _ create_connection
Return _ connectionrecord (Self)
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 318, in _ init __
Self. Connection = self. _ connect ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/pool. py", line 368, in _ connect
Connection = self. _ pool. _ creator ()
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/engine/strategies. py", line 80, in connect
Return dialect. Connect (* cargs, ** cparams)
File "/usr/lib64/python2.6/Site-packages/sqlalchemy/engine/Default. py", line 283, in connect
Return self. dbapi. Connect (* cargs, ** cparams)
File "/usr/lib64/python2.6/Site-packages/psycopg2/_ init _. py", line 164, in connect
Conn = _ connect (DSN, connection_factory = connection_factory, async = async)
Sqlalchemy. exc. operationalerror: (operationalerror) cocould not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
None none
In this case, you only need to check whether the postgresql service is enabled,
Service PostgreSQL status,
If not, just open it,
Service PostgreSQL start