2011-02-11 57 views
0

我在努力使用「Practical Django Projects」這本書,但是這個東西不工作。你可以找到我的代碼到目前爲止here.(沒有「鏈接」類。我剛剛添加了get_absolute_url入門類,突然間我有一個「Caught TypeError,而渲染:不可能的類型:'字典'」錯誤時試圖。去管理頁面Screenie of what I'm talking about.我從來沒有在該文件中修改任何顯示錯誤:(我做這個做什麼Caught TypeError while rendering:unhashable type:'dict'

編輯:?

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) 

從是:添加此之後發生的錯誤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'), 
) 

回答

3

很抱歉,但你代碼目前未加載。

據我猜測,你可能試圖使用dict實例作爲dict鍵。 例如,你不能做到這一點:

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

你能告訴我在URLconf行其中coltrane_entry_detail URL命名?至少one old ticket on djangoproject.com表明錯誤可能是由錯誤配置的url模式引起的,如果您剛剛爲您的模型添加了get_absolute_url方法,我猜你可能剛剛添加了它指向的命名視圖?

+0

在我原來的問題中加入了它。 – Soviet 2011-02-12 09:03:38

0

你有沒有用pip和virtualenv設置django環境?您的項目具有以下依存關係:

markdown==2.0.3 
django-tagging==0.3.1 

我把上面的一個在項目層面稱爲requirements.txt文件。一旦你已經安裝了PIP,virtualenv中,並創造了該項目的一個獨特的環境,你可以安裝在上面:

pip install -r requirements.txt 

以前的設置後,你需要把taggingsettings.pyINSTALLED_APPS

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

刪除您的cms.db數據庫文件並運行python manage.py sycndb。您需要爲超級用戶提供用戶名和密碼。代碼運行良好,我可以訪問管理員。

0

有些時候這全是因爲我們使用HttpResponse實例insted的的渲染方法


對於前: 在我的情況

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

這刪除與

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

相關問題