1

尝试在 Django 上安装 PyBB,尝试启动论坛页面时出错,在新安装的虚拟机上做同样的事情一切正常,在我的 Django 上看起来像问题,可能是什么问题?

TemplateSyntaxError at /forum/

Could not parse the remainder: ':pybb_category_add' from 'admin:pybb_category_add'

Request Method:     GET
Request URL:    http://127.0.0.1:8000/forum/
Django Version:     1.5
Exception Type:     TemplateSyntaxError
Exception Value:    

Could not parse the remainder: ':pybb_category_add' from 'admin:pybb_category_add'

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/template/base.py in __init__, line 570
Python Executable:  /usr/bin/python
Python Version:     2.7.3
Python Path:    

['/home/denis/hosts/blog',
 '/usr/local/lib/python2.7/dist-packages/django_simple_captcha-0.3.5-py2.7.egg',
 '/usr/local/lib/python2.7/dist-packages/pytz-2012h-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']


Error during template rendering

In template /usr/local/lib/python2.7/dist-packages/pybb/templates/pybb/index.html, error at line 17
Could not parse the remainder: ':pybb_category_add' from 'admin:pybb_category_add'
7   {% with extra_crumb="Forum" %}{% include "pybb/breadcrumb.html" %}{% endwith %}
8   {% endblock %}
9   
10  {% block content %}
11  {% if categories %}
12  {% for category in categories %}
13  {% include 'pybb/category.html' %}
14  {% endfor %}
15  {% else %}
16  <h2>{% trans "Forum categories are not created" %}</h2>
17  <a href="{% url admin:pybb_category_add %}">{% trans "Add a category now" %}</a>
18  {% endif %}
19  {% if user.is_authenticated %}
20  <div id='mark-all-as-read'>
21  <a href='{% url pybb:mark_all_as_read %}'>
22  {% trans "Mark all forums as read" %}
23  </a>
24  </div>
25  {% endif %}
26  {% endblock content %}
27  
4

1 回答 1

2

{% url %}使用标签时尝试使用引号:

<a href="{% url 'admin:pybb_category_add' %}">{% trans "Add a category now" %}</a>%}
...
<a href="{% url 'pybb:mark_all_as_read' %}">

从文档:

第一个参数是以 package.package.module.function 格式的视图函数的路径。它可以是带引号的文字或任何其他上下文变量。

于 2013-02-20T16:01:01.717 回答