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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:46:01+00:00 2026-06-15T23:46:01+00:00

I am making a simple blog app in Django as a learning exercise. I

  • 0

I am making a simple blog app in Django as a learning exercise. I am able to add posts, see them all on the front page, so it is working so far. Where I am having an issue is creating a view that shows the whole post on a separate page. I want to click the title, and go to a page at the url /post/primary key that has the title and body. When I click on the link, I get a page with just the base.html. Not sure where I am missing anything, here are urls.py, views.py, and post.html:

urls.py
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('blog.views',
    url(r'^$', 'frontpage'),
    url(r'^post/(\d+)/$', 'post'),
)

urlpatterns += patterns('',
    url(r'^admin/', include(admin.site.urls)),
) 

from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, render_to_response
from blog.models import *

views.py

def frontpage(request):
    posts = Post.objects.all().order_by("-created")
    paginator = Paginator(posts, 5)

    page = request.GET.get('page', '1')

    try: 
        posts = paginator.page(page)
    except (InvalidPage, EmptyPage):
        posts = paginator.page(paginator.num_pages)

    return render_to_response("list.html", dict(posts=posts, user=request.user))

def post(request, pk):
    """Single Post"""
    post = Post.objects.get(pk = pk)
    d = dict(post=post, user=request.user)
    return render_to_response("post.html", d)

post.html

{% extends "base.html" %}

{% block content %}
    <div class ="main">
        <ul>
            {% for post in posts.object_list %}
                <div class = "title">{{ post.title }}</div>
                <ul>
                    <div class="time"> {{ post.created }}</div>
                    <div class ="body"> {{ post.body|linebreaks }}</div>
                </ul>
            {% endfor %}
        </ul>
    </div>
{% endblock %}

Thanks in advance for your help.

  • 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-15T23:46:02+00:00Added an answer on June 15, 2026 at 11:46 pm

    I am assuming the page.html is actually the post.html you have in yoru codes sample???You no longer have a collection of posts but instead just have 1 post

    This needs to change from: (which is looping through your posts)

    {% extends "base.html" %}
    
    {% block content %}
        <div class ="main">
            <ul>
                {% for post in posts.object_list %}
                    <div class = "title">{{ post.title }}</div>
                    <ul>
                        <div class="time"> {{ post.created }}</div>
                        <div class ="body"> {{ post.body|linebreaks }}</div>
                    </ul>
                {% endfor %}
            </ul>
        </div>
    {% endblock %}
    

    To something like (which just displays your single post):

    {% extends "base.html" %}
    
    {% block content %}
        <div class ="main">
            {{ post.title }}
            {{ post.created }}
            {{ post.body }}      
        </div>
    {% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning CakePHP, thus I'm making a simple blog in order to learn basic
I'm making a simple blog Rails app and am trying to output links to
I am making a simple timer app. I have a uitable with multiple rows.
I'm making a simple mediaplayer app that downloads a song from a predetermined URL
I'm making a simple app using the HTML5 <canvas> tag and compile the code
I'm making a simple blog to learn rails. Everything is almost finished, and I'm
I am making a blog app and I want to redirect to a different
I am making a simple blog for myself and while reading through the PHP
I'm making a simple blog in which I will be the sole poster, and
I am making a very simple blog for my PHP project, but am having

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.