Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » URLConf/ManytoManyField issue (exercise problem from Teach Yourself Django in 24 Hour) [RSS Feed]

#1 March 9, 2008 14:16:27

E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

URLConf/ManytoManyField issue (exercise problem from Teach Yourself Django in 24 Hour)


> I can do that, but then I get a key error with the name. However, it  
> works with similar code here:
>
> def details(request, pID='0', opts=()):
> response = HttpResponse()
>         response.write("<HTML><BODY>\n")
>         try:
>                 p = Person.objects.get(id=pID)
>                 if (pID == '0'):
>                         response.write("<H1>Person Details Index</H1><HR>\n")
>                 else:
>
>                         for d in opts:
>                                 response.write("<li>%s: %s</li>" % (d,
> p.__dict__))
>         except Person.DoesNotExist:
>                 response.write("Person Not Found")
>
>         response.write("</BODY></HTML>")
>         return response
>
>
>
> > But, from the error message, I'm guessing that's actually not (yet)
> > your problem. It complains about the 'text' attribute that cannot be
> > found, which would suggest that that field doesn't exist in the actual
> > database (it's there in the model). Did you sync the database, and
> > then later added the text attribute to Blog (or even the whole Blog)?
> > Btw, where in your view is line 53? I'm guessing at "b =
> > Person.objects.get(id=pID)"?
>
> I dropped the database and resynced it. No go.
>
> I then went and changed the URL code to pass the params to the view  
> with this to this:
>
> details4 = {'opts':('name', 'blogs')}
>
> And now I get:
>
> KeyError at /People/Blog/1/
> 'blogs'
>
> Which confused me a bit, since blogs is also a key.
>
> I can probably skip this excercise and proceed on with the rest of the  
> book since I know now how to pass multiple views and have multiple  
> URLs, but this concerns me. Part of me still doesn't understand fully  
> why it is not working and I get a feeling that if I don't resolve  
> this, I probably screw up the rest of the exercises in the book. :|

I would still have a look at that p.__dict__ syntax. I've never
used it, but looking it up, it appears to work slightly different for
class variables and instance variables. Perhaps that's what the
problem is here.
You could try and replace p.__dict__ with p.__getattribute__(d).
See what that gives you. You'll have to ask other people what is
better, although I prefer the latter.
Then again, as said, I would take a completely other approach to the
problem in the first place, but I guess that's not where the book is
at this moment.

Btw, what did you change to details4? It looks exactly the same to me,
other than an extra space between the two keywords.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » URLConf/ManytoManyField issue (exercise problem from Teach Yourself Django in 24 Hour) [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support