On Sat, Oct 10, 2009 at 6:43 PM, Rizwan <mr.mans...@googlemail.com> wrote:

>
> I am trying to extend flatpage view...I have added custom code
> here..you can see navigation showing question mark here
> http://beta.rmansuri.net/homepage/
>
>
> [snip]
>    #custom code start
>    db = MySQLdb.connect
> (user='rmansuri_gq',db='rmansuri_gq',passwd='riz#wan1712',host='localhost')
>    cursor = db.cursor()
>    cursor.execute("SELECT * from django_flatpage where id != 2")
>    details = [row for row in cursor.fetchall()]
>    db.close()
>

Why are you bypassing the Django ORM and creating your own DB connection,
etc. for this?  That's a whole lot of work and you lose all the nice things
the ORM provides you with, including setting up the DB connection so that
MySQL returns data utf-8 encoded instead of its default latin1.  The
question marks are coming from the fact that the data you have can't be
encoded in latin1, so MySQL returns ? for each Unicode character it can't
send over a connection that only accepts latin1.

You could fix your db connection to return utf8, but this whole chunk would
be much more simply written as:

details = FlatPage.objects.exclude(pk=2)

and then in your template instead of:

   {% for id,url, title,content in details %}
       <li><a href="{{url}}">{{title|safe}}</a></li>
   {% endfor %}

you would use:

   {% for fp in details %}
       <li><a href="{{fp.url}}">{{fp.title|safe}}</a></li>
   {% endfor %}

Karen

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to