迁移django 1.1.1 - > 1.2.1:{%url%}不起作用

时间:2010-07-06 13:19:05

标签: python django

我正在将django项目从1.1.1迁移到1.2.1

现在,{% url %}标记既不起作用,也@models.permalink - 装饰get_absulute_url起作用

即。我得到了

TemplateSyntaxError at /
Caught TypeError while rendering: __init__() got an unexpected keyword argument 'error_message'

代表

<li><a href="{% url archive_talks %}">talks</a></li>

虽然url-pattern看起来像这样:

url(r'^archive/talks/$', 'talkapp.views.archive_talks', name="archive_talks"),

有没有人遇到同样的问题?有解决方案吗?

回溯

Environment:

Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.2.1
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.humanize',
 'django.contrib.markup',
 'pinax.templatetags',
 'notification',
 'django_openid',
 'emailconfirmation',
 'django_extensions',
 'robots',
 'mailer',
 'messages',
 'announcements',
 'oembed',
 'djangodblog',
 'pagination',
 'threadedcomments',
 'threadedcomments_extras',
 'timezones',
 'voting',
 'voting_extras',
 'tagging',
 'blog',
 'ajax_validation',
 'avatar',
 'flag',
 'locations',
 'uni_form',
 'django_sorting',
 'django_markup',
 'staticfiles',
 'analytics',
 'profiles',
 'account',
 'signup_codes',
 'tag_app',
 'topics',
 'groups',
 'django.contrib.admin',
 'smartif',
 'annoying',
 'haystack',
 'talkapp']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django_openid.consumer.SessionConsumer',
 'account.middleware.LocaleMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'pagination.middleware.PaginationMiddleware',
 'django_sorting.middleware.SortingMiddleware',
 'djangodblog.middleware.DBLogMiddleware',
 'pinax.middleware.security.HideSensistiveFieldsMiddleware',
 'django.middleware.transaction.TransactionMiddleware')


Template error:
In template /Users/vikingosegundo/Coding/horizonte/social/templates/base.html, error at line 76
   Caught TypeError while rendering: __init__() got an unexpected keyword argument 'error_message'
   66 :             </ul>


   67 :             </div>


   68 :             {% endif %}


   69 :             


   70 :              {% get_sorted_items talkapp.semester all by -semesterStart as semesters %}


   71 : 


   72 :             {% if semesters%}


   73 :             <div class="portlet">


   74 :             <h3>Archive</h3>


   75 :             <ul>


   76 :                 <li><a href=" {% url archive_of_talks     %} ">talks</a></li>


   77 :                 <li><a href="{% url archive_of_lectures  %}">persons</a></li>


   78 :                 <li><a href="{% url archive_of_semesters %}">semester</a></li>


   79 :             </ul>


   80 :             <ul>


   81 :             {% for n in semesters %}


   82 :                 <li>


   83 :                     <a href="{{ n.get_absolute_url }}">{{ n.semester_name    }}</a>


   84 :                 </li>


   85 :             {% endfor %}


   86 :             </ul>


Traceback:
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/views/generic/simple.py" in direct_to_template
  18.     return HttpResponse(t.render(c), mimetype=mimetype)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  173.             return self._render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django_smartif-0.1-py2.6.egg/smartif/templatetags/smartif.py" in render
  278.             return self.nodelist_true.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/template/defaulttags.py" in render
  366.             url = reverse(self.view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in reverse
  350.             *args, **kwargs)))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in reverse
  271.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  193.             self._populate()
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _populate
  173.                     for name in pattern.reverse_dict:
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  193.             self._populate()
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _populate
  162.         for pattern in reversed(self.url_patterns):
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
  243.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  238.             self._urlconf_module = import_module(self.urlconf_name)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/pinax/apps/blog/urls.py" in <module>
  3. from blog import views, models
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/pinax/apps/blog/views.py" in <module>
  13. from blog.forms import *
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/pinax/apps/blog/forms.py" in <module>
  7. class BlogForm(forms.ModelForm):
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/pinax/apps/blog/forms.py" in BlogForm
  11.         error_message = _("This value must contain only letters, numbers, underscores and hyphens."))
File "/Users/vikingosegundo/Coding/horizonte/pinax-env/lib/python2.6/site-packages/django/forms/fields.py" in __init__
  184.         super(CharField, self).__init__(*args, **kwargs)

Exception Type: TemplateSyntaxError at /
Exception Value: Caught TypeError while rendering: __init__() got an unexpected keyword argument 'error_message'

1 个答案:

答案 0 :(得分:4)

此问题与实际{% url %}标记无关。您在该标签上点击它的原因是URL反转过程实际上导入了所有Django视图,并且在完全不同的地方出现错误:BlogForm类。

如果没有该表单的代码,很难确切地告诉那里有什么错误,虽然它确实传递了error_message参数,而不是error_messages(带有s)。