Permalink
Browse files

Switch away from /tmp for windows users

  • Loading branch information...
1 parent e95cef6 commit 9074bc46af69f168e059dc977f90bbeb6d250077 @mitsuhiko mitsuhiko committed Feb 8, 2014
Showing with 16 additions and 6 deletions.
  1. +14 −5 docs/tutorial/setup.rst
  2. +2 −1 examples/flaskr/flaskr.py
@@ -27,7 +27,7 @@ config from the same file, in `flaskr.py`::
# Load default config and override config from an environment variable
app.config.update(dict(
- DATABASE='/tmp/flaskr.db',
+ DATABASE=os.path.join(app.root_path, 'flaskr.db'),
DEBUG=True,
SECRET_KEY='development key',
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
can update it with new values.
-.. admonition:: Windows
+.. admonition:: Database Path
- If you are on Windows, replace `/tmp/flaskr.db` with a different writeable
- path of your choice, in the configuration and for the rest of this
- tutorial.
+ Operating systems know the concept of a current working directory for
+ each process. Unfortunately you cannot depend on this in web
+ 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
configuration file. Flask allows you to import multiple configurations and it
@@ -10,6 +10,7 @@
:license: BSD, see LICENSE for more details.
"""
+import os
from sqlite3 import dbapi2 as sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
@@ -20,7 +21,7 @@
# Load default config and override config from an environment variable
app.config.update(dict(
- DATABASE='/tmp/flaskr.db',
+ DATABASE=os.path.join(app.root_path, 'flaskr.db'),
DEBUG=True,
SECRET_KEY='development key',
USERNAME='admin',

0 comments on commit 9074bc4

Please sign in to comment.