On Sunday 07 February 2010 10:49:03 jimgardener wrote: > Thanks Mike for the reply. > > I rewrote the method as > @models.permalink > def get_absolute_url(self): > return("myapp_entry_detail",(),{'id':self.id}) > > When I go to the admin interface's edit page for an entry and click > the viewsite button it causes the following error, > NoReverseMatch,Reverse for 'myapp_entry_detail' with arguments '()' > and keyword arguments '{'id': 6}' not found. > > When I try in browser http://127.0.0.1:8000/myapp/1/ causes > ValueError,dictionary update sequence element #0 has length 1; 2 is > required > > is this caused by the name 'myapp_entry_detail' in the urlpattern > below? > (r'^(?P<id>\d+)/$','myapp.views.entry_detail','myapp_entry_detail'), > > The following is the entry_detail method which I defined > def entry_detail(request,id): > entry=MyEntry.objects.get(id=id) > entry_detail_dict={'object':entry} > return render_to_response('myapp/ > myentry_detail.html',entry_detail_dict) > > I can't figure out why these errors are occuring..Everything works > fine when I hardcode the url and omit the name 'myapp_entry_detail' in > the urlpattern.If I don't omit that name in urlpattern ,the Request > URL http://127.0.0.1:8000/myapp/1/ causes the ValueError which I > mentioned earlier. >
See the link below and you want your pattern to be like this url(r'^(?P<id>\d+)/$','myapp.views.entry_detail',name='myapp_entry_detail'), Actually read this whole page, but this anchor is the important part, and the reverse() towards the bottom http://docs.djangoproject.com/en/dev/topics/http/urls/#url and for completeness reread through this again: http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permalink- decorator In the end tho, I usually just use the name='' in the url() pattern along with the **kwargs as described before. But make sure you understand those two pages and you should be able to get it working perfect. Mike -- Magnocartic, adj.: Any automobile that, when left unattended, attracts shopping carts. -- Sniglets, "Rich Hall & Friends"
signature.asc
Description: This is a digitally signed message part.