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 8984345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:04:58+00:00 2026-06-15T21:04:58+00:00

I’m looking to build a small ‘Twitter style’ site using Django to get to

  • 0

I’m looking to build a small ‘Twitter style’ site using Django to get to grips with things and have decided to try and allow multiple users edit each post (eventually based on permissions). Now what I’m struggling with is accessing each user’s posts. Below is the code for my model, view and template which shows “There aint no post here” for all users. I’m looking to be able to show all posts that the user has and don’t seem to be getting anywhere:

models.py

from django.db import models

class User(models.Model):
    username = models.CharField(max_length = 200)
    email = models.EmailField(max_length = 75)
    password = models.CharField(max_length = 64)
    created_date = models.DateTimeField('date created')

    def __unicode__(self):
        return self.username

    class Meta:
        ordering = ('created_date',)


class Post(models.Model):
    users = models.ManyToManyField(User)
    title = models.CharField(max_length = 300)
    post = models.TextField()
    posted_date = models.DateTimeField('date created')
    votes = models.IntegerField()

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ('posted_date',)

views.py

from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse

from users.models import User, Post

def index(request):
    latest_user_list = User.objects.order_by('username')[:5]
    context = {'latest_user_list': latest_user_list}
    return render(request, 'users/index.html', context)

def detail(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    post_list = Post.objects.filter(id == user.id)  
    return render(request, 'users/detail.html', {'user': user, 'post': post_list})

urls.py

from django.conf.urls import patterns, url

from users import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^(?P<user_id>\d+)/$', views.detail, name='detail'),
)

(template) – detail.html

<h1>{{ user.username }}</h1>
{% if post_list %}
    <ul>
    {% for post in post_list%}
        <li>{{ post.title }}</li>
    {% endfor %}
    </ul>
{% else %}
    <p> There aint no posts here </p>
{% endif %}
  • 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-15T21:04:59+00:00Added an answer on June 15, 2026 at 9:04 pm

    The variable you’re passing to the template is called post not post_list.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.