Skip to content
Myr

Switch away from /tmp for windows users

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent e95cef6 · Browse files · 2 files+16 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−6 removed

  • other:+16 added−6 removed

2 files+16 added−6 removed

modified:docs/tutorial/setup.rst+14 added-5 removed
25 unmodified lines
26 app.config.from_object(__name__)2728 # Load default config and override config from an environment variable29 app.config.update(dict(30 DATABASE='/tmp/flaskr.db',30 DATABASE=os.path.join(app.root_path, 'flaskr.db'),31 DEBUG=True,32 SECRET_KEY='development key',33 USERNAME='admin',34 PASSWORD='default'
2 unmodified lines
3738The :class:`~flask.Config` object works similar to a dictionary so we39can update it with new values.4041.. admonition:: Windows41.. admonition:: Database Path4243 If you are on Windows, replace `/tmp/flaskr.db` with a different writeable44 path of your choice, in the configuration and for the rest of this45 tutorial.43 Operating systems know the concept of a current working directory for44 each process. Unfortunately you cannot depend on this in web45 applications because you might have more than one application in the46 same process.4748 For this reason the ``app.root_path`` attribute can be used to49 get the path to the application. Together with the ``os.path`` module50 files can then easily be found. In this example we place the51 database right next to it.5253 For a real-work application it's recommended to use54 :ref:`instance-folders` instead.5556Usually, it is a good idea to load a separate, environment specific57configuration file. Flask allows you to import multiple configurations and it 58will use the setting defined in the last import. This enables robust 59configuration setups. :meth:`~flask.Config.from_envvar` can help achieve this.
59 unmodified lines
modified:examples/flaskr/flaskr.py+2 added-1 removed
8 unmodified lines
9 :copyright: (c) 2014 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213import os14from sqlite3 import dbapi2 as sqlite315from flask import Flask, request, session, g, redirect, url_for, abort, \16 render_template, flash17
2 unmodified lines
20app = Flask(__name__)2122# Load default config and override config from an environment variable23app.config.update(dict(23 DATABASE='/tmp/flaskr.db',24 DATABASE=os.path.join(app.root_path, 'flaskr.db'),25 DEBUG=True,26 SECRET_KEY='development key',27 USERNAME='admin',28 PASSWORD='default'
81 unmodified lines