Code

Opened 9 years ago

Closed 7 years ago

#93 closed defect (fixed)

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

Reported by: xtian@… Owned by: adrian
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: UI/UX:

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)

Attachments (0)

Change History (6)

comment:1 Changed 9 years ago by adrian

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

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

comment:2 Changed 9 years ago by richie@…

  • Resolution fixed deleted
  • Severity changed from normal to major
  • Status changed from closed to reopened

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 Changed 9 years ago by richie@…

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 Changed 9 years ago by adrian

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

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

comment:5 Changed 7 years ago by Madison

  • Cc jryfibofbvc added
  • Component changed from Tools to Cache system
  • Keywords jryfibofbvc added
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Design decision needed
  • Version set to 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 Changed 7 years ago by adrian

  • Cc jryfibofbvc removed
  • Component changed from Cache system to Tools
  • Keywords jryfibofbvc removed
  • Resolution set to fixed
  • Status changed from reopened to closed
  • Version other branch deleted

Reverted spam.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.