python - Can I make the Django database path (for sqlite3) "cross-platform"? -


i'm in process of learning django , python (as programming in general). sake of simplicity, using sqlite3 database while i'm going through tutorials django , such.

i multi-platform user (mac os, windows, linux) depending on @ time. so, have done put programming projects in dropbox can work on same code anywhere.

the problem that, in settings.py file particular project, specify database path so:

databases = {     'default': {     'engine': 'django.db.backends.sqlite3',                             # add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.     'name': 'c:/users/david/dropbox/programming/mysite/database',       # or path database file if using sqlite3. 

... when i'm using macos or linux, c:/ chokes. wondering if had suggestion of simple remedy this. of course, 1 way set database remotely on webserver via mysql or something, thought there might simple way such 'if' statement.

using relative paths in settings.py common enough considered best practice many. may help.

from os.path import dirname, join  project_dir = dirname(__file__)  databases = {     # ...     'name': join(project_dir, 'your_db_name.db'),     # ... } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -