How can I log both successful and failed login and logout attempts in Django?

You could hook up to the provided signals: django.contrib.auth.signals Recording to log import logging from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed from django.dispatch import receiver log = logging.getLogger(__name__) @receiver(user_logged_in) def user_logged_in_callback(sender, request, user, **kwargs): # to cover more complex cases: # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django ip = request.META.get(‘REMOTE_ADDR’) log.debug(‘login user: {user} via ip: {ip}’.format( user=user, ip=ip )) @receiver(user_logged_out) def … Read more

How to use visual studio code to debug django

For VSCode (full disclosure, I’m one of the VSCode developers) try installing the Python extension to get started. This documentation covers debugging Django. There should be a included debug configuration or you can add your own to the launch.json file: { “name”: “Django”, “type”: “python”, “request”: “launch”, “stopOnEntry”: false, “pythonPath”: “${config.python.pythonPath}”, “program”: “${workspaceRoot}/manage.py”, “args”: [ … Read more

InterfaceError: connection already closed (using django + celery + Scrapy)

Unfortunately this is a problem with django + psycopg2 + celery combo. It’s an old and unsolved problem. Take a look on this thread to understand: https://github.com/celery/django-celery/issues/121 Basically, when celery starts a worker, it forks a database connection from django.db framework. If this connection drops for some reason, it doesn’t create a new one. Celery … Read more

Django: Best way to merge migrations conflicts

From the Django docs: Because migrations are stored in version control, you’ll occasionally come across situations where you and another developer have both committed a migration to the same app at the same time, resulting in two migrations with the same number. Don’t worry – the numbers are just there for developers’ reference, Django just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)