views:

39

answers:

2

I am getting a TemplateSyntaxError, that is only happening on my dev server, but works fine on the django testing server locally.

Here's the error

Caught SyntaxError while rendering: invalid syntax (urls.py, line 1)

and the html:

<li><a href="{% url plan.views.profile %}">Plan Details</a></li>

and here is the profile view:

@login_required
def profile(request):
...

here's the traceback:

Traceback:
File "/django/lib/python2.5/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/django/lib/python2.5/django/contrib/auth/decorators.py" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "/django/myapp/plan/views.py" in profile
  121.             }, context_instance=RequestContext(request) )
File "/django/lib/python2.5/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/django/lib/python2.5/django/template/loader.py" in render_to_string
  186.     return t.render(context_instance)
File "/django/lib/python2.5/django/template/__init__.py" in render
  173.             return self._render(context)
File "/django/lib/python2.5/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "/django/lib/python2.5/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/loader_tags.py" in render
  139.             return self.template.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  173.             return self._render(context)
File "/django/lib/python2.5/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/defaulttags.py" in render
  253.             return self.nodelist_false.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/defaulttags.py" in render
  253.             return self.nodelist_false.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/defaulttags.py" in render
  251.             return self.nodelist_true.render(context)
File "/django/lib/python2.5/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/django/lib/python2.5/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/django/lib/python2.5/django/template/defaulttags.py" in render
  366.             url = reverse(self.view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/django/lib/python2.5/django/core/urlresolvers.py" in reverse
  350.             *args, **kwargs)))
File "/django/lib/python2.5/django/core/urlresolvers.py" in reverse
  271.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/django/lib/python2.5/django/core/urlresolvers.py" in _get_reverse_dict
  193.             self._populate()
File "/django/lib/python2.5/django/core/urlresolvers.py" in _populate
  173.                     for name in pattern.reverse_dict:
File "/django/lib/python2.5/django/core/urlresolvers.py" in _get_reverse_dict
  193.             self._populate()
File "/django/lib/python2.5/django/core/urlresolvers.py" in _populate
  162.         for pattern in reversed(self.url_patterns):
File "/django/lib/python2.5/django/core/urlresolvers.py" in _get_url_patterns
  243.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/django/lib/python2.5/django/core/urlresolvers.py" in _get_urlconf_module
  238.             self._urlconf_module = import_module(self.urlconf_name)
File "/django/lib/python2.5/django/utils/importlib.py" in import_module
  35.     __import__(name)

I've check my urls.py file and it is fine. The first line is:

from django.conf.urls.defaults import *
+1  A: 

In your urls.py use named urls via url function ie.

urlpatterns = patterns('your_app.views',
    url(r'^somehiing/$', 'your_view_function', name='my_view'),
)

Then in your template use {% url my_view %}.

If it will not help, paste here your urls.py - maybe it's just some tiny syntax error.

bx2
I think my url pattern is fine, because it is working fine locally and I think django would throw a different error if I had made a syntax error in the urls.py file.
bababa
Not necessarily. You can have a `url()` that works fine for serving the page (forwards resolution) but won't work with `reverse()`; forward and reverse resolution are relatively independent. Please paste the line from `urls.py` that has the `plan.views.profile` view.
Mike DeSimone
try the ars' suggestion and if it will not work paste the urls.py - that's all I can tell for now.
bx2
I've tried reversing it, and it works fine. Here is the line: (r'^$', 'profile'),
bababa
Don't be so shy :) paste some more with initial patterns definition :)
bx2
Solved it, totally un-related via had an svn commit that didn't finish. Fixed, and it fix the problem.
bababa
That's great :)
bx2
A: 

Here's one possibility. The path to your views file seems to be /django/myapp/plan/views.py:

File "/django/myapp/plan/views.py" in profile
    121.             }, context_instance=RequestContext(request) )

If your python path is configured to include /django, then you'll need to change your template/html to:

{% url myapp.plan.views.profile %}

If this isn't the case, then per bx2's suggestion, you might want to check your urls.py file for syntax errors.

ars