I'm coding a small application with Django. But I can't see any error logs in the console when an error (e.g. Python syntax error, etc.) occurs in one of my views -no action at all.
How can I see the error logs of my views? Debugging like a blind is really annoying.
Django does not print any errors to the console by default. Instead it provides very helpful error pages that are displayed for any errors that occur in your views. Please check what your DEBUG setting is set to. In development this should be True which will give you the nice error pages for 404 and 500 errors.
The pretty error page will look like this:
(source: linkaider.com)
I can also recommend the talk What the Heck Went Wrong? from DjangoCon2009 for some more information on basic debugging technics with django.
Related
I've gotten use to using print in my python code to show contents of variable and checking the shell output.
But i have now migrated all my work onto a online server. Pythonanywhere
I don't have the foggiest idea how to do the same now?
Can someone point me in the right direction?
Print to web console? To a file? Or even to the shell session?
Thanks
On production server your print statements will output log to your webserver log files
In case of pythonanywhere there are three log files
Access log:yourusername.pythonanywhere.com.access.log
Error log:yourusername.pythonanywhere.com.error.log
Server log:yourusername.pythonanywhere.com.server.log
those logs are accessible in your web tab page.
The logs you are looking for will be in server.log
As mentioned in Serjik's answer you can see the output of the console via the server log link on PythonAnywhere.
However the much better way to approach this is to use the Python logging module.. Using this module will solve many of these problems for you and solve many issues you may not have thought about (like thread safety). This lets you do things like filter log messages by severity and a whole bunch of other things.
To get started with that I would recommend having a look at the basic logging tutorial.
I'm serving an app through IIS6. An error is occurring preventing the app from working, I am not 100% sure what it might be.
I believe the following is generated by python, but I am not entirely sure.
"A server error has occurred. Please contact the administrator"
Any ideas on figuring out what is actually going on?
It looks more like web server error (500?).
Is debugging enabled? You should be able to see exception message and traceback. Also, check web server error log and define settings.ADMINS. This is usefull in production when debugging is disabled:
When DEBUG=False and a view raises an exception, Django will e-mail these people with the full exception information.
http://docs.python.org/library/logging.html#simple-examples
import logging
logging.debug('foobar')
Quite often the error reports coming via e-mail are less than useful in tracking bugs. Most often this is due to missing session data and username of the user triggering the error. Is there a project or a library I could use to get more complete error reports?
You could write your own exception middleware, as suggested here (bottom of page).
There is a base snippets here and an example of how to extract the traceback here
I love django, and I like flex. Django for it's cool debugging system (those yellow pages helps a lot to find bugs in my code), and flex for it possibilities.
Recently I come across a problem. If I create a form in flex and then communicate with the django server, I can't see any debugging info (when the exception happens in django).
Not sure, if there is a way to get the debugging info, because it is not accessible in command line (no error output), or in firebug....
Also I tried to create a quick html form, and post same data as I send from flex form, but it's a bit of pain to be honest.
Will be happy to listen how do you solve the problem
I've used firebug to debug the flex side of things. But I've been using json or XML for communication between the two. Since flash uses the browser to do the network stuff, the request should be visible in the net tab of firebug.
To debug the django side of things, you have a few options.
If you're using the django dev server, you can add print statements to find out what's going on.
You can write a unit test to see if the django side of things is doing what you expect it to, given known data.
You can use the pyDev debugger to run the django dev server and step through your code.
I use a combination of these to debug my code.
i have been on this for the last 2 days with no result.
i am running my facebook app on my localhost with port-forwarding method.
i know my server setup is working fine as i can see the logs on the django runserver and dyndns log as well.
django is properly responding to calls as well.
the problem is as soon as the app authorizes with my user account, it straight follows to the page that says this:
Errors while loading page from application
The URL http://amitverma.dyndns.org/facebook_sample/?auth_token=817f8fbe99eff10582b634589de17b84 is not valid.
Please try again later. We appreciate your patience as the developers of app_test and Facebook resolve this issue. Thanks!
I am making a test app learning from facebook + django tutorial from here and here.
I am still getting this error and I have no idea what i am doing wrong...
Please help me out.
This often happens with a failed authentication. I'm not sure what the Python client libraries might look like, but with the PHP ones you generally make an authorization call against the library, something like $facebook->require_login().
With the PHP library, if this call fails to verify the user's Facebook session, then it automatically outputs HTML that will redirect the browser and try to re-establish the session, hence the auth_token parameter.
I suspect you're running into something similar. Try to isolate any authentication calls you're making, and use a Firefox extension like LiveHTTPHeaders to see if you are undergoing any redirects during the requests.
When you get that error, presuming you have debug=True in the Django settings and that your application is in development mode in Facebook, you can do View Source and see the entire Django error page that would normally display, including traceback. Facebook comment it out in the HTML so it doesn't show on the front end, but you can copy and paste it into a separate HTML file and view that in your browser to see the nice friendly Django error page which will definitely give you a clue as to what's going wrong.