Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

602
Views
AttributeError: 'AnonymousUser' object has no attribute 'profile'

I have built a Django app and it worked well. When I had run an another django app in a port(localhost:8000) and tried the app I built on the port, it says error like this.

AttributeError: 'AnonymousUser' object has no attribute 'profile'

Here is my code:

class DashboardView(auth_views.LoginView):
    template_name = "dashboard/home.html"
    verify_email_required = 'registration/verify_email_required.html'
    form_class = ProfiledAuthenticationForm
    def get(self, request, *args, **kwargs):
        # context = {'form': self.form_class()}
        
        context = self.get_context_data()
        context['form'] = self.form_class()
        
        if request.user.profile.is_verified:        
            return render(request, self.template_name, context)
        else:           
            
            return render(request, self.verify_email_required, context)

Note: Initial when I built the app, it worked well, but for now it takes error. when user does not log in, the homepage was redirected to login page.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When I fixed like this, it runs well.

class DashboardView(auth_views.LoginView):
    template_name = "dashboard/home.html"
    verify_email_required = 'registration/verify_email_required.html'
    form_class = ProfiledAuthenticationForm
    def get(self, request, *args, **kwargs):
        # context = {'form': self.form_class()}
        
        context = self.get_context_data()
        context['form'] = self.form_class()
        if self.request.user.is_authenticated:
            if request.user.profile.is_verified:        
                return render(request, self.template_name, context)
            return render(request, self.verify_email_required, context)
        return render(request, self.template_name, context)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!