Opened 7 years ago

Closed 7 years ago

#8371 closed (fixed)

Windows users should use / instead of \ for file paths in settings.py

Reported by: pariksheet Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by mtredinnick)

Please put a warning in settings.py or the tutorial page that Windows users must only use / not \ in their file paths.

When trying to run the step of python manage.py syncdb in the tutorial -
http://www.djangoproject.com/documentation/tutorial01/
The command kept throwing the following error -

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python25\Lib\site-packages\django\core\management\__init__.py", line
334, in execute_manager
    utility.execute()
  File "C:\Python25\Lib\site-packages\django\core\management\__init__.py", line
295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python25\Lib\site-packages\django\core\management\base.py", line 77,
in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python25\Lib\site-packages\django\core\management\base.py", line 96,
in execute
    output = self.handle(*args, **options)
  File "C:\Python25\Lib\site-packages\django\core\management\base.py", line 178,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python25\Lib\site-packages\django\core\management\commands\syncdb.py"
, line 51, in handle_noargs
    cursor = connection.cursor()
  File "C:\Python25\Lib\site-packages\django\db\backends\__init__.py", line 56,
in cursor
    cursor = self._cursor(settings)
  File "C:\Python25\Lib\site-packages\django\db\backends\sqlite3\base.py", line
144, in _cursor
    self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file

The solution was changing the \ to / in my file path for my sqlite database in DATABASE_NAME of settings.py

Change History (9)

comment:1 Changed 7 years ago by adamv

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This is likely a SQLITE specific thing; Python otherwise doesn't mind / path separators on Windows.

comment:2 Changed 7 years ago by mtredinnick

  • Description modified (diff)

(Fixed description formatting)

This ticket is very confusing. The title and the description are suggesting different changes and there's no actual of the actual setting you were using for comparison. Please clarify what the actual problem is.

comment:3 Changed 7 years ago by Karen Tracey <kmtracey@…>

From experimentation, you get the error cited in the description if you include backslashes, e.g.: DATABASE_NAME = 'c:\tmp\playground'. Changing that to DATABASE_NAME = 'c:/tmp/playground' avoids the error. (There's already an admonition to always use forward slashes down in the comments on the TEMPLATE_DIRS, but for the initial syncdb users probably haven't read that far down.)

comment:4 Changed 7 years ago by ramiro

This was solved in [9010] for part of the tutorial by adding an admonition in the relevant place. What's left to be decided is if a similar admonition should be added to the project settings.py file template next to the DATABASE_NAME settting. That will dictate the status of this ticket.

comment:5 Changed 7 years ago by ramiro

Should have been "This was solved in [9010] for part one of the tutorial"

comment:6 Changed 7 years ago by kmtracey

  • Summary changed from Windows users should use \ instead of / for file paths in settings.py to Windows users should use / instead of \ for file paths in settings.py

Made title match description. The problem with the \s is that the either need to be doubled or in a raw string. That's standard Python, so if it's mentioned in the tutorial now I'm not sure it necessary to also put it in settings itself, though I suppose it wouldn't hurt.

comment:7 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [9084]) Fixed #8371: Added a note warning Windows users about the use of forward slashes when specifying the DATABASE_NAME setting.

comment:8 Changed 7 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

This is just plain wrong.

While using "forward" slashes works, the correct path seperator on windows is "\".
The actual problem is that people don't seem to know about raw strings (or using
).

So the note should be changed to read sth. like:

file. When specifying the path on windows, remember to use double backslashes.
(e.g. C:
homes
user
mysite
sqlite3.db).

comment:9 Changed 7 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from reopened to closed

Well, no, it's not wrong, since forward slashes work perfectly well. So I don't see any reason to get into discussions of raw strings or doubled backslashes in comments in the settings file. Forward slashes work, and they're easier, let's leave it at that.

Note: See TracTickets for help on using tickets.
Back to Top