73

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 %} 
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
xpanta
  • 8,124
  • 15
  • 60
  • 104

10 Answers10

143

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?

Garry Cairns
  • 3,005
  • 1
  • 18
  • 33
  • Thanks, I just did a grep in my virtualevn and it seems that `grapelli` has to do something with it. Is it fixable? – xpanta Oct 18 '13 at 04:56
  • 5
    Ok, I changed `{% url admin:password_change as password_change_url %}` to `{% url 'admin:password_change' as password_change_url %}` (added the single quotes) and it seems to work. Single quotes need to be added to other places, too. The file that needs to be changed is this: `lib/python2.7/site-packages/grappelli/templates/admin/includes_grappelli/header.html`. – xpanta Oct 18 '13 at 05:34
  • 6
    I would like to add that I got this error when use `{{}}` when I should have been using `{%%}` – Clint Nov 28 '17 at 20:22
11

For me it was using {{ }} instead of {% %}:

href="{{ static 'bootstrap.min.css' }}"  # wrong
href="{% static 'bootstrap.min.css' %}"  # right
ReemRashwan
  • 341
  • 3
  • 8
5

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 %}
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
user13493827
  • 51
  • 1
  • 1
2

In templates/admin/includes_grappelli/header.html, line 12, you forgot to put admin:password_change between '.

The url Django tag syntax should always be like:

{% url 'your_url_name' %}
Tms91
  • 3,456
  • 6
  • 40
  • 74
1

also happens when you use jinja templates (which have different syntax for calling object methods) and you forget to set it in settings.py

Michel Samia
  • 4,273
  • 2
  • 24
  • 24
  • {% csrf_token %} Can you find the error in this code.Pizzacart is a list containing details related to pizzas and pizza represents each of them. – Irfan wani Aug 09 '20 at 04:01
1

Template Syntax Error: is due to many reasons one of them is {{ post.date_posted|date: "F d, Y" }} is the space between colon(:) and quote (") if u remove the space then it work like this ..... {{ post.date_posted|date:"F d, Y" }}

Ziar Khan
  • 301
  • 3
  • 3
  • This doesn't seem to be the cause of the syntax error in this question, based on the error message. – kaya3 Feb 11 '20 at 06:45
1

You have indented part of your code in settings.py:

# 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',

Therefore, it is giving you an error.

advaiyalad
  • 144
  • 1
  • 11
1

for me, when I checked if condition: This made error: {%if number==10 %} This solved error: {% if number == 10 %} #you may notice about space!

0

Make sure you are using static files and URLs properly

<link href="{% static 'css/semantic.min.css' %}" rel="stylesheet">
  • Check it is properly surrounded with quotation marks or not
  • Check beginning and ending brackets
  • Check tag is closed properly or not
MD SHAYON
  • 7,001
  • 45
  • 38
0

I got the same error below:

django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: ':test' from 'my_app1:test'

Because I didn't use quotes for my_app1:test with url tag as shown below. *Since Django 1.5, quotes have been needed:

<a href="{% url my_app1:test %}">Test</a>
            {% ↑ No quotes  ↑ %}

So, I used quotes for my_app1:test with url tag as shown below, then the error was solved:

<a href="{% url 'my_app1:test' %}">Test</a>
             {% ↑   quotes   ↑ %}
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129