Soviet
Soviet

Reputation: 119

Caught TypeError while rendering: unhashable type: 'dict'

I'm trying really hard to work with the book "Practical Django Projects", but this stuff it's not working. You can find my code so far here. (Without the "Link" class. I've just added the get_absolute_url Entry class and all of a sudden I have a "Caught TypeError while rendering: unhashable type: 'dict'" error when trying to get to admin page. Screenie of what I'm talking about. I've never modified anything in that file showed in the error :(. What do i do with this?

EDIT: bug occurred after adding this:

def get_absolute_url(self):
    return ('coltrane_entry_detail', (), { 'year': self.pub_date.strftime("%Y"),
                                           'month': self.pub_date.strftime("%b").lower(),
                                           'day': self.pub_date.strftime("%d"),
                                           'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)

That's from urls.py:

urlpatterns = patterns('django.views.generic.date_based',
    (r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'),
    (r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/?(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'),
)

Upvotes: 0

Views: 4650

Answers (4)

GrvTyagi
GrvTyagi

Reputation: 4497

Some time this comes when we use HTTPResponse instance insted of render method


For ex: In my case

return HttpResponse(request, 'doctor_list.html', {'list': doctor_list})

This remove with

return render(request, 'doctor_list.html', {'list': doctor_list})

Upvotes: 0

Thierry Lam
Thierry Lam

Reputation: 46294

Do you have your django environment setup with pip and virtualenv? Your project has the following dependencies:

markdown==2.0.3
django-tagging==0.3.1

I've put the above in a file called requirements.txt at your project level. Once you have installed pip, virtualenv and created a unique environment for that project, you can install the above as:

pip install -r requirements.txt

After the previous setup, you need to put tagging in INSTALLED_APPS of your settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.flatpages',
    'cms.search',
    'coltrane',
    'tagging',
)

Delete your cms.db database file and run python manage.py sycndb. You will need to provide a username and password for the superuser. The code is running fine on my end and I can access the admin.

Upvotes: 0

Hipikat
Hipikat

Reputation: 145

can you show me the line in your URLconf in which the coltrane_entry_detail url is named? At least one old ticket on djangoproject.com suggests that error may be caused by a misconfigured url pattern, and if you've just added a get_absolute_url method for your model I'm guessing you may have also just added the named view it refers to?

Upvotes: 1

ikostia
ikostia

Reputation: 7597

Sorry, but your code isn't loading at the moment.

As far as I can guess you're probably trying to use dict instance as a dict key. For example, you can't do this:

a = {'1' : 'one'}
b = {a : 'two'}

Upvotes: 3

Related Questions