Why is Django reverse() failing with unicode?

Posted by JeffS on Stack Overflow See other posts from Stack Overflow or by JeffS
Published on 2010-04-20T22:10:14Z Indexed on 2010/04/20 22:13 UTC
Read the original article Hit count: 389

Filed under:
|
|

Here is a django models file that is not working as I would expect. I would expect the to_url method to do the reverse lookup in the urls.py file, and get a url that would correspond to calling that view with arguments supplied by the Arguments model.

from django.db import models
class Element(models.Model):
    viewname = models.CharField(max_length = 200)
    arguments = models.ManyToManyField('Argument', null = True, blank = True )

    @models.permalink
    def to_url(self):
        d = dict( self.arguments.values_list('key', 'value') )
        return (self.viewname, (), d)
class Argument(models.Model):
    key = models.CharField(max_length=200)
    value = models.CharField(max_length=200)

The value d ends up as a dictionary from a unicode string to another unicode string, which I believe, should work fine with the reverse() method that would be called by the permalink decorator, however, it results in:

TypeError: reverse() keywords must be strings

© Stack Overflow or respective owner

Related posts about django

Related posts about python