|
Posted by Pinniped |
|
|
I'd like to capture the GET/POST access notification that Django by default prints to the terminal. How do I go about logging those? I know that I could alternatively add logging statements to the appropriate views in my Django module, but having to add an additional line to every view seems like an ugly solution when something else is already noting the same information.
Is there any way to repurpose those print statements as log statements? Can it be done as a change to the Django project/module, without modifying Django directly? Thank you very much. |
|
|
Posted by zeinab |
|
|
did you use "@login_required" decorator?
you can use a method for logging in then just use "@login_required" in the top of the definition of every method that requires logged in users also you have to add these lines to your settings.py file: LOGIN_URL = '/login/' LOGOUT_URL = '/logout/' you can use your own templates instead of "login" and "logout" after that when ever an anonymous user wants to use a @login_required page, he/she would redirect to the login page and also after log out, would redirect to the logout page you should keep in mind that you should use redirect in the method tat you have wrote for the login in your view files i hope it helps good luck |
|
|
Posted by Pinniped |
|
|
Thanks for your response! That wasn't exactly the issue I was having, though -- it's not an authentication issue, but a logging one, including the activity and ip addresses of anonymous users.
I never figured out how to capture the stuff that Django prints to the console by default (aside from just piping it into a file, but (a) I wanted to move away from "print" to use proper loggers instead, and (b) I didn't want to have to fuss with Apache to make that happen), but I was able to write a piece of Middleware that does what I need it to. Very simply, I have a piece of middleware with a process_request function which grabs request.user, request.META["REMOTE_ADDR"] and request.META["PATH_INFO"], sends that information to a logger, then passes the request on. I can post my code if anyone's interested, but I don't think I've done anything particularly interesting. |


