I created a django project to retrive the transaction data from database by verifying the user. But i am getting error like"AnonymousUser"

def view_transaction(request):
    print(request.user)
    user_transactions = Transactions.objects.filter(user_account = request.user)
    return render(request,'transactions.html',{'user_transactions':user_transactions})

is the above code correct or not, i think when it check wheather user login is not present here.

models.py

class User(models.Model):
    name = models.CharField(max_length=45)
    phone = models.CharField(max_length=45)
    account_number = models.CharField(max_length=45,primary_key=True,blank=False,unique=True)
    user_id = models.CharField(max_length=45,unique=True)
    password = models.CharField(max_length=45)
    confirm_password = models.CharField(max_length=45)

class Transactions(models.Model):
    transaction_number = models.AutoField(primary_key=True)
    user_account = models.ForeignKey(User,on_delete=models.CASCADE)
    date_of_transaction = models.DateField()
    transaction_type = models.CharField(max_length=20, choices=TRANSACTION_TYPES)
    transaction_medium = models.CharField(max_length=20, choices=TRANSACTION_MEDIUM)
    transaction_amount = models.DecimalField(max_digits=10,decimal_places=2)

when i login using userid and password ,it shows some details about customer. I want transaction details in transactions.html,but i didn’t get any, instead i got error like anonymous user.

Please post the complete error message being received, along with the full traceback.

i added login_required before view_transaction function

Page not found (404)

Using the URLconf defined in transaction.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. [name=‘signup’]
  3. login/ [name=‘login’]
  4. add_transactions/ [name=‘add_transactions’]
  5. transactions/ [name=‘transactions’]

The current path, accounts/login/, didn’t match any of these.

I think the error message is pretty straight-forward and clear here.

You’re trying to access a url “accounts/login/”, but you don’t have that URL defined.

If you’re trying to use the system-provided views, review the docs at Using the Django authentication system | Django documentation | Django