Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: TemplateSyntaxError: Could not parse the remainder

I am getting this issue when I type localhost:8000/admin/.

`TemplateSyntaxError: Could not parse the remainder: ':password_change' from 'admin:password_change'. The syntax of 'url' changed in Django 1.5, see the docs.

Here's part of my 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', ) 

Did I do anything wrong?

PS: This is my full traceback https://gist.github.com/anonymous/e8c1359d384df7a6b405

EDIT:

I am pasting the output of grep as per request:

$ 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 %}  
like image 698
xpanta Avatar asked Oct 17 '13 13:10

xpanta


People also ask

Could not parse the remainder Django error?

But if you look at it carefully, you will think the error message is very helpful and clear TemplateSyntaxError: Could Not Parse The Remainder. The error is because of the Django static tag's argument 'css/dept_emp_style. css', the single quote( ' ) is not an English character. Instead, it is a Chinese character.

What does Could not parse the remainder mean?

This error usually means you've forgotten a closing quote somewhere in the template you're trying to render. For example: {% url 'my_view %} (wrong) instead of {% url 'my_view' %} (correct). In this case it's the colon that's causing the problem. Normally you'd edit the template to use the correct {% url %} syntax.

How do you sort data in a Django template?

To order them in the view I would need to iterate through the events and for each event create a container of some sort of the attendees related to that event in properly sorted order, then pass that entire collection of containers to the template in a form that would let the template find the appropriate collection of ...

Which option does Django templates accept?

DjangoTemplates engines accept the following OPTIONS : 'autoescape' : a boolean that controls whether HTML autoescaping is enabled. It defaults to True . Only set it to False if you're rendering non-HTML templates!


2 Answers

This error usually means you've forgotten a closing quote somewhere in the template you're trying to render. For example: {% url 'my_view %} (wrong) instead of {% url 'my_view' %} (correct). In this case it's the colon that's causing the problem. Normally you'd edit the template to use the correct {% url %} syntax.

But there's no reason why the django admin site would throw this, since it would know it's own syntax. My best guess is therefore that grapelli is causing your problem since it changes the admin templates. Does removing grappelli from installed apps help?

like image 100
Garry Cairns Avatar answered Oct 02 '22 18:10

Garry Cairns


There should not be a space after name.

Incorrect:

{% url 'author' name = p.article_author.name.username %} 

Correct:

{% url 'author' name=p.article_author.name.username %} 
like image 22
user13493827 Avatar answered Oct 02 '22 17:10

user13493827