Opened 19 years ago

Closed 17 years ago

#93 closed defect (fixed)

django-admin startproject can create invalid settings/admin.py on windows

Reported by: xtian@… Owned by: Adrian Holovaty
Component: Tools Version:
Severity: major Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Following part 2 of the tutorial, I get the following error when trying to view /admin/:

There's been an error:
Traceback (most recent call last):

File "C:\play\python\django\trunk\django\core\handlers\wsgi.py", line 187, in get_response

response = middleware_method(request, callback, param_dict)

File "C:\play\python\django\trunk\django\middleware\admin.py", line 46, in process_view

return self.display_login_form(request, message)

File "C:\play\python\django\trunk\django\middleware\admin.py", line 91, in display_login_form

t = template_loader.get_template(self.get_login_template_name())

File "C:\play\python\django\trunk\django\core\template_loader.py", line 13, in get_template

return get_template_from_string(load_template_source(template_name))

File "C:\play\python\django\trunk\django\core\template_file.py", line 22, in load_template_source

raise TemplateDoesNotExist, error_msg

TemplateDoesNotExist: Tried C:\\play\\python\\django\trunk\\django/conf/admin_templates\\login.html

The \t in django\trunk is a tab character.

This is coming from the settings/admin.py file created by django-admin startproject. At line 349 in django-admin.py, where it is populating the TEMPLATE_DIRS setting, the %r format specifier should be used to ensure that the path is rendered correctly into the file, and r needs to be put in the string before it to ensure that it is interpreted as a raw string.

So line 349 should be:

settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "
1\n r%r,
2)" % ADMIN_TEMPLATE_DIR, settings_contents)

Change History (6)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [322]) Fixed #93 -- Fixed 'django-admin startproject' to use os.path.join instead of string concatenation

comment:2 by richie@…, 19 years ago

Resolution: fixed
Severity: normalmajor
Status: closedreopened

This bug seems to have been reintroduced. Going through the tutorial doesn't work on Windows. Here's a patch that fixes it:

*** C:\src\tests\django\trunk\django\core\.svn\text-base\management.py.svn-base 2005-08-05 08:34:02.000000000 +-0100
--- C:\src\tests\django\trunk\django\core\management.py 2005-08-05 10:16:22.000000000 +-0100
***************
*** 357,369 ****
      _start_helper('project', project_name, directory)
      # Populate TEMPLATE_DIRS for the admin templates, based on where Django is
      # installed.
      admin_settings_file = os.path.join(directory, project_name, 'settings/admin.py')
      settings_contents = open(admin_settings_file, 'r').read()
      fp = open(admin_settings_file, 'w')
!     settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n    '%s',\\2)" % ADMIN_TEMPLATE_DIR, settings_contents)
      fp.write(settings_contents)
      fp.close()
      # Create a random SECRET_KEY hash, and put it in the main settings.
      main_settings_file = os.path.join(directory, project_name, 'settings/main.py')
      settings_contents = open(main_settings_file, 'r').read()
      fp = open(main_settings_file, 'w')
--- 357,370 ----
      _start_helper('project', project_name, directory)
      # Populate TEMPLATE_DIRS for the admin templates, based on where Django is
      # installed.
      admin_settings_file = os.path.join(directory, project_name, 'settings/admin.py')
      settings_contents = open(admin_settings_file, 'r').read()
      fp = open(admin_settings_file, 'w')
!     four_backslash_quoted_dir = ADMIN_TEMPLATE_DIR.replace('\\', '\\\\\\\\')
!     settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n    '%s',\\2)" % four_backslash_quoted_dir, settings_contents)
      fp.write(settings_contents)
      fp.close()
      # Create a random SECRET_KEY hash, and put it in the main settings.
      main_settings_file = os.path.join(directory, project_name, 'settings/main.py')
      settings_contents = open(main_settings_file, 'r').read()
      fp = open(main_settings_file, 'w')

comment:3 by richie@…, 19 years ago

Here's a much neater fix:

*** C:\src\tests\django\trunk\django\core\.svn\text-base\management.py.svn-base 2005-08-05 08:34:02.000000000 +-0100
--- C:\src\tests\django\trunk\django\core\management.py 2005-08-05 13:25:28.000000000 +-0100
***************
*** 357,369 ****
      _start_helper('project', project_name, directory)
      # Populate TEMPLATE_DIRS for the admin templates, based on where Django is
      # installed.
      admin_settings_file = os.path.join(directory, project_name, 'settings/admin.py')
      settings_contents = open(admin_settings_file, 'r').read()
      fp = open(admin_settings_file, 'w')
!     settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n    '%s',\\2)" % ADMIN_TEMPLATE_DIR, settings_contents)
      fp.write(settings_contents)
      fp.close()
      # Create a random SECRET_KEY hash, and put it in the main settings.
      main_settings_file = os.path.join(directory, project_name, 'settings/main.py')
      settings_contents = open(main_settings_file, 'r').read()
      fp = open(main_settings_file, 'w')
--- 357,369 ----
      _start_helper('project', project_name, directory)
      # Populate TEMPLATE_DIRS for the admin templates, based on where Django is
      # installed.
      admin_settings_file = os.path.join(directory, project_name, 'settings/admin.py')
      settings_contents = open(admin_settings_file, 'r').read()
      fp = open(admin_settings_file, 'w')
!     settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n    r%r,\\2)" % ADMIN_TEMPLATE_DIR, settings_contents)
      fp.write(settings_contents)
      fp.close()
      # Create a random SECRET_KEY hash, and put it in the main settings.
      main_settings_file = os.path.join(directory, project_name, 'settings/main.py')
      settings_contents = open(main_settings_file, 'r').read()
      fp = open(main_settings_file, 'w')

comment:4 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: reopenedclosed

(In [498]) Fixed #93 and #279 -- 'django-admin startproject' no longer creates invalid settings/admin.py on Windows

comment:5 by Madison, 17 years ago

Cc: jryfibofbvc added
Component: ToolsCache system
Keywords: jryfibofbvc added
Resolution: fixed
Status: closedreopened
Triage Stage: UnreviewedDesign decision needed
Version: other branch

vizit+for+more+info+click+to++%5BURL%3D+http%3A%2F%2Fvisit.lv.com+%5Dvizit%5B%2FURL%5D+%0D%0A+about++%3Ca+href%3D+http%3A%2F%2Fvisit.lv.net+%3Evizit+information%3C%2Fa%3E+%0D%0A++http%3A%2F%2Fvisit.lv.org+vizit++about%0D%0Av

comment:6 by Adrian Holovaty, 17 years ago

Cc: jryfibofbvc removed
Component: Cache systemTools
Keywords: jryfibofbvc removed
Resolution: fixed
Status: reopenedclosed
Version: other branch

Reverted spam.

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