当我输入localhost:8000/admin/
时,我得到了这个问题。
` `TemplateSyntaxError:无法分析'admin:password_change‘中的余数:':password_change’。在Django 1.5中,'url‘的语法发生了变化,请参阅文档。
这是我的settings.py
的一部分
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'filebrowser',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
#'django.contrib.admindocs',
'tinymce',
'sorl.thumbnail',
'south',
'django_facebook',
'djcelery',
'devserver',
'main',
)
AUTH_USER_MODEL = 'django_facebook.FacebookCustomUser'
AUTHENTICATION_BACKENDS = (
'django_facebook.auth_backends.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
# Uncomment the following to make Django tests pass:
'django.contrib.auth.backends.ModelBackend',
)
我做错什么了吗?
PS:这是我的完整回溯https://gist.github.com/anonymous/e8c1359d384df7a6b405
编辑:
我根据请求粘贴grep的输出:
$ ack-grep --type=python -r ':password_change' .
lib/python2.7/site-packages/django/contrib/admin/sites.py
264:url = reverse('admin:password_change_done', current_app=self.name)
lib/python2.7/site-packages/grappelli/dashboard/dashboards.py
147:reverse('%s:password_change' % site_name)],
$ ack-grep --type=html -r ':password_change' .
lib/python2.7/site-packages/django/contrib/admin/templates/admin/base.html
36:<a href="{% url 'admin:password_change' %}">{% trans 'Change password' %}</a> /
lib/python2.7/site-packages/grappelli/templates/admin/includes_grappelli/header.html
12:{% url admin:password_change as password_change_url %}
发布于 2013-10-18 00:08:02
此错误通常意味着您忘记了要呈现的模板中的某个地方的右引号。例如:{% url 'my_view %}
(错误)而不是{% url 'my_view' %}
(正确)。在这种情况下,是冒号导致了问题。通常,您需要编辑模板以使用正确的{% url %}
syntax。
但是django管理站点没有理由抛出这个错误,因为它知道自己的语法。因此,我最好的猜测是grapelli
导致了您的问题,因为它更改了管理模板。从已安装的应用程序中删除grappelli是否有帮助?
发布于 2020-05-08 04:15:44
name
后面不应该有空格。
不正确:
{% url 'author' name = p.article_author.name.username %}
正确:
{% url 'author' name=p.article_author.name.username %}
发布于 2020-04-12 19:33:47
在templates/admin/includes_grappelli/header.html,第12行中,您忘记将admin:password_change
放在'
之间。
url Django标记语法应始终如下所示:
{% url 'your_url_name' %}
https://stackoverflow.com/questions/19428572
复制相似问题