diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 4b40009..151b94e 100644
a
|
b
|
def setup_environ(settings_mod, original_settings_path=None):
|
323 | 323 | else: |
324 | 324 | os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) |
325 | 325 | |
326 | | # Import the project module. We add the parent directory to PYTHONPATH to |
| 326 | # Import the project module. We add the parent directory to PYTHONPATH to |
327 | 327 | # avoid some of the path errors new users can have. |
328 | 328 | sys.path.append(os.path.join(project_directory, os.pardir)) |
329 | 329 | project_module = import_module(project_name) |
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index c08ecc4..e5b2101 100644
a
|
b
|
class URLNode(Node):
|
371 | 371 | try: |
372 | 372 | url = reverse(self.view_name, args=args, kwargs=kwargs) |
373 | 373 | except NoReverseMatch: |
374 | | project_name = settings.SETTINGS_MODULE.split('.')[0] |
375 | | try: |
376 | | url = reverse(project_name + '.' + self.view_name, |
377 | | args=args, kwargs=kwargs) |
378 | | except NoReverseMatch: |
| 374 | if settings.SETTINGS_MODULE is None: |
| 375 | # SETTINGS_MODULE is not set, so we can't guess the "main" app. |
379 | 376 | if self.asvar is None: |
380 | 377 | raise |
| 378 | else: |
| 379 | project_name = settings.SETTINGS_MODULE.split('.')[0] |
| 380 | try: |
| 381 | url = reverse(project_name + '.' + self.view_name, |
| 382 | args=args, kwargs=kwargs) |
| 383 | except NoReverseMatch: |
| 384 | if self.asvar is None: |
| 385 | raise |
381 | 386 | |
382 | 387 | if self.asvar: |
383 | 388 | context[self.asvar] = url |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index c511222..c45daf3 100644
a
|
b
|
class Templates(unittest.TestCase):
|
152 | 152 | split = token.split_contents() |
153 | 153 | self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")']) |
154 | 154 | |
| 155 | def test_url_reverse_no_settings_module(self): |
| 156 | #Regression test for #9005 |
| 157 | from django.template import Template, Context, TemplateSyntaxError |
| 158 | old_settings_module = settings.SETTINGS_MODULE |
| 159 | settings.SETTINGS_MODULE = None |
| 160 | t = Template('{% url will_not_match %}') |
| 161 | c = Context() |
| 162 | try: |
| 163 | rendered = t.render(c) |
| 164 | except TemplateSyntaxError, e: |
| 165 | #Assert that we are getting the template syntax error and not the |
| 166 | #string encoding error. |
| 167 | self.assertEquals(e.message, "Caught an exception while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.") |
| 168 | settings.SETTINGS_MODULE = old_settings_module |
| 169 | |
155 | 170 | def test_templates(self): |
156 | 171 | template_tests = self.get_template_tests() |
157 | 172 | filter_tests = filters.get_filter_tests() |