Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:43:17+00:00 2026-06-09T11:43:17+00:00

Im using the below code in my views.py page to render a html page.

  • 0

Im using the below code in my views.py page to render a html page. This piece of code is from a Django book and im trying to understand the bookmark_set attribute.

views.py

def user_page(request, username):
    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        raise Http404(u'Requested user not found')

    bookmarks = user.bookmark_set.all()

    template = get_template('user_page.html')

    variables = Context({'username':username, 'bookmarks':bookmarks})

    output = template.render(variables)
    return HttpResponse(output)

models.py

from django.db import models
from django.contrib.auth.models import User

class Link(models.Model):
    url = models.URLField(unique=True)

class Bookmark(models.Model):
    title = models.CharField(max_length=200)
    user  = models.ForeignKey(User)
    link  = models.ForeignKey(Link)

When I run this piece of code in my Python shell, I get the following error

from django.contrib.auth.models import User
from bookmarks.models import *
user=User.object.get(id=1)
user.bookmark_set.all()

Attribute Error: ‘User’ object has no attribute ‘bookmark_set’

Why do I get this error?

How does the set attribute of the User work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:43:18+00:00Added an answer on June 9, 2026 at 11:43 am

    The bookmark_set attribute provides a convenient way to traverse the reverse relationship, i.e. to get all of a user’s bookmarks. You can read more about it in the docs:

    Django also creates API accessors for the “other” side of the relationship — the link from the related model to the model that defines the relationship. For example, a Blog object b has access to a list of all related Entry objects via the entry_set attribute: b.entry_set.all().

    You can actually specify the name of the reverse relationship attribute by providing a related_name in your model:

    class Bookmark(models.Model):
        user  = models.ForeignKey(User, related_name="bookmarks")
    
    $ myuser.bookmarks.all()
    

    Have you definitely created your models in the DB by running python manage.py syncdb? It looks like you are doing everything correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a web page using the below code QWebView *view
I wanted to generate a list view using below code. But after running this
I am using below code to generate photo gallery from a folder. How can
I'm using below code to check some form fields and render datatable table on
I have this piece of code which i am using on another area of
I'm getting the following error when trying to produce an HTML page using Jade.
I am displaying a web page using the below code. But the title always
i am using below code to change the the font type of text view.
I am using vb.net code. I have grid view, please see the code below:
I am using below code to upload excel and INSERT in mysql in php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.