Browse Source

Switch away from /tmp for windows users

pull/929/merge
Armin Ronacher 11 years ago
parent
commit
9074bc46af
  1. 19
      docs/tutorial/setup.rst
  2. 3
      examples/flaskr/flaskr.py

19
docs/tutorial/setup.rst

@ -27,7 +27,7 @@ config from the same file, in `flaskr.py`::
# Load default config and override config from an environment variable # Load default config and override config from an environment variable
app.config.update(dict( app.config.update(dict(
DATABASE='/tmp/flaskr.db', DATABASE=os.path.join(app.root_path, 'flaskr.db'),
DEBUG=True, DEBUG=True,
SECRET_KEY='development key', SECRET_KEY='development key',
USERNAME='admin', USERNAME='admin',
@ -38,11 +38,20 @@ config from the same file, in `flaskr.py`::
The :class:`~flask.Config` object works similar to a dictionary so we The :class:`~flask.Config` object works similar to a dictionary so we
can update it with new values. can update it with new values.
.. admonition:: Windows .. admonition:: Database Path
If you are on Windows, replace `/tmp/flaskr.db` with a different writeable Operating systems know the concept of a current working directory for
path of your choice, in the configuration and for the rest of this each process. Unfortunately you cannot depend on this in web
tutorial. applications because you might have more than one application in the
same process.
For this reason the ``app.root_path`` attribute can be used to
get the path to the application. Together with the ``os.path`` module
files can then easily be found. In this example we place the
database right next to it.
For a real-work application it's recommended to use
:ref:`instance-folders` instead.
Usually, it is a good idea to load a separate, environment specific Usually, it is a good idea to load a separate, environment specific
configuration file. Flask allows you to import multiple configurations and it configuration file. Flask allows you to import multiple configurations and it

3
examples/flaskr/flaskr.py

@ -10,6 +10,7 @@
:license: BSD, see LICENSE for more details. :license: BSD, see LICENSE for more details.
""" """
import os
from sqlite3 import dbapi2 as sqlite3 from sqlite3 import dbapi2 as sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, \ from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash render_template, flash
@ -20,7 +21,7 @@ app = Flask(__name__)
# Load default config and override config from an environment variable # Load default config and override config from an environment variable
app.config.update(dict( app.config.update(dict(
DATABASE='/tmp/flaskr.db', DATABASE=os.path.join(app.root_path, 'flaskr.db'),
DEBUG=True, DEBUG=True,
SECRET_KEY='development key', SECRET_KEY='development key',
USERNAME='admin', USERNAME='admin',

Loading…
Cancel
Save