On Sat, 2006-06-10 at 10:37 +0000, Giovanni Giorgi wrote:
> Hi all,
>  I am building a small blog, based on the code of the wamber website.
> I have a fuzzy problem: when I insert a new posting adding a 'slug' to
> it, then I cannot search for it based on its slug name.
> I am recieving a 'No post found for' error. Sometimes it seems working,
> sometime I get an error.
> I think it was a caching problem (I am running via mod_python) but it
> is not.
> DB is postgres and Python is 2.4.1
> 
> The url I find is in the form:
> http://localhost:7000/blog/2006/06/10/singles-cucinare/
> and the matching url expression is in the sub module 'blog' and is
> something like (file urls.py):
> 
> from django.conf.urls.defaults import *
> from blog.models import Post
> jj_blog_dict= {
>         'queryset': Post.objects.all(),
>         'date_field': 'date',
>         'month_format': '%m',
> 
> }
> 
> urlpatterns = patterns('django.views.generic.date_based',
> [...]
> (r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>.+)/$',
> 'object_detail', dict(jj_blog_dict, slug_field='slug')),
> [...]
> 
> I'd like to have a strong debug (trace mode) to detect where is the
> problem, and a log of which url pattern is chosen.
> How can enable it (DEBUG is True but I have no log...)?

We don't log this information, because it's easy enough to put any
debugging clues you want in the function that should be called. In this
case, add a print statement or something to
django/views/generic/date_based.py in the object_detail() function. That
will tell you whether you are getting that far. If you were actually
throwing an error, the traceback would be reported (with DEBUG = True),
so that is not happening to you.

> 
> I'd like to see the django query... but where I can insert the debug
> line suggested on
> http://www.djangoproject.com/documentation/faq/#how-can-i-see-the-raw-sql-queries-django-is-running
> ?

Around line 302 in object_detail(), there is a line that says

        obj = queryset.get(**lookup_kwargs)
        
I would try getting the information from connection.queries just after
that  statement runs. You may need to put something like "print obj" in
there first, just to force the SQL to execute (remember that a QuerySet
is lazy, so it isn't evaluated until you really need the results). So
something like

        obj = queryset.get(**lookup_kwargs)
        print
        print obj
        import pprint
        pprint.pprint(connection.queries[-5])
        print

should be useful. Note that this is kind of assuming you are using the
development server (so prints just go to the terminal window where you
started the development server). If you are using mod_python or
something, you may well want to write these results to a file or use the
logging module that is standard with Python.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to