Re: print_r() in Django & SQL debug output

2009-05-03 Thread Dan Mallinger

Hi Okto,

I feel confident saying that Malcolm knows the ins and outs of Django
far better than I do :) But, for what it's worth, I really like the
logging package here:
http://code.google.com/p/django-logging/wiki/Overview
It's super easy and reasonably powerful.  And if you install Sphinx,
it'll look more beautiful than anything that ever comes out of
CakePHP.
I'll also take this moment to say: As someone who's worked with
CakePHP quite a bit, Django is a wonderful, wonderful change!

Cheers to Malcolm and everyone else on the team,
Dan

On Sat, May 2, 2009 at 11:02 PM, Malcolm Tredinnick
 wrote:
>
> On Sun, 2009-05-03 at 09:48 +0700, Okto Silaban wrote:
>> On Sun, May 3, 2009 at 9:27 AM, Malcolm Tredinnick
>>  wrote:
>>
>>
>>
>>         How are you rendering that template? The only thing I can
>>         think of that
>>         will go wrong here is if you do not pass a RequestContext to
>>         render_to_response() -- or whatever rendering method you are
>>         using.
>>         Context processors only run if the context is a
>>         RequestContext, not
>>         simply a Context object.
>>
>>         See this documentation (esp. the "note" callout):
>>         http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
>>
>> Thanx.. You're right, I forgot to add this as the third parameter :
>> context_instance=RequestContext(request)
>>
>> And, how about my first question ?
>>
>> 1. What Django template tags can I use to replace print_r() /
>> var_dump() in PHP?
>
> There are no direct equivalents, because Django templates are at a
> different level and provide different functionality to PHP files.
> However, there are a few things you can do for viewing the context and
> seeing things in "pretty printed" format. Here are a bunch of ideas I
> wrote up recently:
> http://www.pointy-stick.com/blog/2009/02/03/some-simple-django-debugging-tools/
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Malcolm Tredinnick

On Sun, 2009-05-03 at 09:48 +0700, Okto Silaban wrote:
> On Sun, May 3, 2009 at 9:27 AM, Malcolm Tredinnick
>  wrote:
> 
> 
> 
> How are you rendering that template? The only thing I can
> think of that
> will go wrong here is if you do not pass a RequestContext to
> render_to_response() -- or whatever rendering method you are
> using.
> Context processors only run if the context is a
> RequestContext, not
> simply a Context object.
> 
> See this documentation (esp. the "note" callout):
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 
> 
> Thanx.. You're right, I forgot to add this as the third parameter :
> context_instance=RequestContext(request)
> 
> And, how about my first question ? 
> 
> 1. What Django template tags can I use to replace print_r() /
> var_dump() in PHP?

There are no direct equivalents, because Django templates are at a
different level and provide different functionality to PHP files.
However, there are a few things you can do for viewing the context and
seeing things in "pretty printed" format. Here are a bunch of ideas I
wrote up recently:
http://www.pointy-stick.com/blog/2009/02/03/some-simple-django-debugging-tools/

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



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Okto Silaban
On Sun, May 3, 2009 at 9:27 AM, Malcolm Tredinnick  wrote:

>
> How are you rendering that template? The only thing I can think of that
> will go wrong here is if you do not pass a RequestContext to
> render_to_response() -- or whatever rendering method you are using.
> Context processors only run if the context is a RequestContext, not
> simply a Context object.
>
> See this documentation (esp. the "note" callout):
> http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
>

Thanx.. You're right, I forgot to add this as the third parameter :
context_instance=RequestContext(request)

And, how about my first question ?

1. What Django template tags can I use to replace print_r() / var_dump() in
PHP?

regards,
okto.silaban.net

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Malcolm Tredinnick

On Sun, 2009-05-03 at 07:47 +0700, Okto Silaban wrote:
> 
> 
> On Sun, May 3, 2009 at 7:04 AM, George Song  wrote:
> 
> 
> Django has extensive documentation. It's advisable that you
> look it up
> first before asking:
> 
> 
> 
> 
> Default :
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG 
> 
> 
> And I've added this in settings.py :
> 
> TEMPLATE_CONTEXT_PROCESSORS = (
> "django.core.context_processors.auth",
> "django.core.context_processors.debug",
> "django.core.context_processors.i18n"
> )
> 
> INTERNAL_IPS = ('127.0.0.1',)
> 
> And added these lines in my template file  :
> 
> 
>   Queries
>   
> {{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
> {% ifnotequal sql_queries|length 0 %}
> (Show)
> {% endifnotequal %}
>   
>   
> 
> 
> 
> 
> 
>   #
>   SQL
>   Time
> 
> 
> 
> {% for query in sql_queries %}
>   {{ forloop.counter }}
>   {{ query.sql|escape }}
>   {{ query.time }}
> {% endfor %}
> 
>   
> 
> 
> This is the output : 
> Queries
> 0 Query (Show) 

How are you rendering that template? The only thing I can think of that
will go wrong here is if you do not pass a RequestContext to
render_to_response() -- or whatever rendering method you are using.
Context processors only run if the context is a RequestContext, not
simply a Context object.

See this documentation (esp. the "note" callout):
http://docs.djangoproject.com/en/dev/ref/templates/api/#id1

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



Re: print_r() in Django & SQL debug output

2009-05-02 Thread Okto Silaban
On Sun, May 3, 2009 at 7:04 AM, George Song  wrote:

Django has extensive documentation. It's advisable that you look it up
> first before asking:
>
> <
> http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-debug
> >


Default :
DEBUG = True
TEMPLATE_DEBUG = DEBUG

And I've added this in settings.py :

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n"
)

INTERNAL_IPS = ('127.0.0.1',)

And added these lines in my template file  :


  Queries
  
{{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
{% ifnotequal sql_queries|length 0 %}
(Show)
{% endifnotequal %}
  
  





  #
  SQL
  Time



{% for query in sql_queries %}
  {{ forloop.counter }}
  {{ query.sql|escape }}
  {{ query.time }}
{% endfor %}

  


This is the output :
Queries
0 Query (Show)

Meanwhile, it does do query.. As these lines show correct DB output :


{% for item in items %}


{{item.nominal}} :

{{ item.category.name }}
 -
{{item.info}}
{% if item.location.location %}
@{{ item.location.location }}
{% endif %}
[3:53]

[x]



 {% endfor %}


regards,
Okto.silaban.net

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r() in Django & SQL debug output

2009-05-02 Thread George Song

On 5/2/2009 4:53 PM, Okto Silaban wrote:
> Ok, I know this is not a PHP mailing list.. I just want to make the 
> question simpler.
> 
> I'm coming from CakePHP background.
> 
> 1. What Django template tags can I use to replace print_r() / var_dump() 
> in PHP?
> 2. How can I display SQL debug output?
> 
> *in cakePHP I can use debug() function to show the SQL debug. So I can 
> see what SQL query it runs
> 
> debug output example :
> 
> SELECT * FROM myapp_entry

Django has extensive documentation. It's advisable that you look it up 
first before asking:



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Don Arbow

On Oct 16, 2006, at 1:30 PM, Rob Hudson wrote:
>
> On Oct 16, 1:00 pm, "Terry" <[EMAIL PROTECTED]> wrote:
>> Easiest way I've found to do it is to add the following as the first
>> two lines of the view function that you want to debug:
>>
>> import pdb
>> pdb.run_trace()
>>
>> Then, when you attempt to load the view, you will get the (pdb)  
>> prompt
>> at your development server, and you can print variables, single step,
>> set breakpoints, etc.
>
> I was trying to see what this did but I get an error that there is no
> run_trace() method in pdb.  In looking at pdb from the Python shell, I
> see this is true.  At least for my Python version (2.3.5).  Did you
> mean another method?  If so, could you explain more?



The method is actually called pdb.set_trace().

Don



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Terry

Rob Hudson wrote:

> I was trying to see what this did but I get an error that there is no
> run_trace() method in pdb.  In looking at pdb from the Python shell, I
> see this is true.  At least for my Python version (2.3.5).  Did you
> mean another method?  If so, could you explain more?

No, that was the method.  I admit that I am using python2.5, but
according to http://www.python.org/doc/2.3.5/lib/module-pdb.html , this
method is in 2.3.5 as well.

- Terry


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Steven Armstrong

On 10/16/06 21:11, Rob Hudson wrote:
> On Oct 16, 11:17 am, Steven Armstrong <[EMAIL PROTECTED]> wrote:
>> A djangofied version of this [1] would be cool.
>>
>> [1]http://pythonpaste.org/screencasts/evalerror-screencast.html
> 
> I agree.  That would be very useful.  One could argue that it should
> only be accessible when running under WSGI.  Would that make it easier
> to implement?
> 

I believe the django dev server runs on top of WSGI. So it shouldn't be 
to difficult to integrate that. I'll have a look at it next time I have 
a moment. Unless someone else beats me to it that is (hint, hint)
  ;)


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Terry

code enquest wrote:
> in PhP i used to print_r(array) to see what if got in my array that I
> want to bring on the screen. Smarty even had a popup screen to show this.
>
> How can I see in Django what I got in the view? So that working in the
> template goes a tat faster? What is the print_r($array) in the template
> or Django version?
>
> Enquest

I have found it very useful to fire up the python debugger from inside
the Django development server.

Easiest way I've found to do it is to add the following as the first
two lines of the view function that you want to debug:

import pdb
pdb.run_trace()

Then, when you attempt to load the view, you will get the (pdb) prompt
at your development server, and you can print variables, single step,
set breakpoints, etc.

- Terry


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Steven Armstrong

On 10/16/06 17:43, Rob Hudson wrote:
> [EMAIL PROTECTED] wrote:
>> I quite often plug in a nonsense command e.g. "fudge" just to raise the
>> debug page, maybe with a few
> 
> I do the same.  It would be awesome if there were a "debugger" app
> (contrib app anyone?) that we could load in the template:
> 
> {{ debugger }}
> 
> That would show a unobtrusive link that when clicked would open a full
> debug window like the ones on template errors with local variables,
> etc.  I've seen some WSGI presentations where you can even have a
> Python shell with those variables.  That sounds like it takes some work
> to store those but something like this would be very useful for Django.
> 
> -Rob
> 

A djangofied version of this [1] would be cool.

[1] http://pythonpaste.org/screencasts/evalerror-screencast.html

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Rob Hudson

[EMAIL PROTECTED] wrote:
> I quite often plug in a nonsense command e.g. "fudge" just to raise the
> debug page, maybe with a few

I do the same.  It would be awesome if there were a "debugger" app
(contrib app anyone?) that we could load in the template:

{{ debugger }}

That would show a unobtrusive link that when clicked would open a full
debug window like the ones on template errors with local variables,
etc.  I've seen some WSGI presentations where you can even have a
Python shell with those variables.  That sounds like it takes some work
to store those but something like this would be very useful for Django.

-Rob


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-16 Thread Dirk Eschler

Am Sonntag, 15. Oktober 2006 00:01 schrieb [EMAIL PROTECTED]:
> I quite often plug in a nonsense command e.g. "fudge" just to raise the
> debug page, maybe with a few
>
> x = dir(some_var)
>
> .. to see what's in them. Once the Django debug page is up, you can
> have a really good poke around with things.
>
> The other alternative is the shell, which is great for working out what
> methods/attributes have, and tracking down the best way to use the
> DB-api etc.
>
> --Simon

How do you do that in the admin interface?

When i have a syntax error in my model, about all i get is a 404 and a note 
that the app/model wasn't found. Not very helpful to track down the source of 
the error. ;)

-- 
Dirk Eschler 
http://www.krusader.org

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-14 Thread [EMAIL PROTECTED]

I quite often plug in a nonsense command e.g. "fudge" just to raise the
debug page, maybe with a few

x = dir(some_var)

.. to see what's in them. Once the Django debug page is up, you can
have a really good poke around with things.

The other alternative is the shell, which is great for working out what
methods/attributes have, and tracking down the best way to use the
DB-api etc.

--Simon


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-14 Thread Steven Armstrong

On 10/14/06 20:11, code enquest wrote:
> Steven Armstrong schreef:
>> On 10/14/06 19:46, code enquest wrote:
>>   
>>> in PhP i used to print_r(array) to see what if got in my array that I 
>>> want to bring on the screen. Smarty even had a popup screen to show this.
>>>
>>> How can I see in Django what I got in the view? So that working in the 
>>> template goes a tat faster? What is the print_r($array) in the template 
>>> or Django version?
>>>
>>> Enquest
>>>
>>> 
>>
>> http://www.djangoproject.com/documentation/templates/#debug
>>
>> Not exactly what you're after, but maybe it helps anyway.
>>
>>   
> I was looking at this but I'm afraid I don't understand how to implement 
> it correct. Maybe you could elaborate on it.
> 

Put {% debug %} somewhere in your template.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-14 Thread code enquest

Steven Armstrong schreef:
> On 10/14/06 19:46, code enquest wrote:
>   
>> in PhP i used to print_r(array) to see what if got in my array that I 
>> want to bring on the screen. Smarty even had a popup screen to show this.
>>
>> How can I see in Django what I got in the view? So that working in the 
>> template goes a tat faster? What is the print_r($array) in the template 
>> or Django version?
>>
>> Enquest
>>
>> 
>
> http://www.djangoproject.com/documentation/templates/#debug
>
> Not exactly what you're after, but maybe it helps anyway.
>
>   
I was looking at this but I'm afraid I don't understand how to implement 
it correct. Maybe you could elaborate on it.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: print_r

2006-10-14 Thread Bryan L. Fordham

code enquest wrote:

>in PhP i used to print_r(array) to see what if got in my array that I
>want to bring on the screen. Smarty even had a popup screen to show this.
>
>How can I see in Django what I got in the view? So that working in the
>template goes a tat faster? What is the print_r($array) in the template
>or Django version?
>
>  
>
you might want to look at the PrettyPrinter 
http://docs.python.org/lib/module-pprint.html

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---