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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:50:57+00:00 2026-06-16T02:50:57+00:00

I have a Django app called blogengine which does exactly what the name implies.

  • 0

I have a Django app called blogengine which does exactly what the name implies. I can’t seem to get data from blogengine (posts) to display in templates when they’re called by flatpages. I’m new to Django but I assume this is a urls.py issue.

My urls.py:

from django.conf.urls.defaults import patterns, include, url
from blogengine.views import PostsFeed

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

urlpatterns = patterns('',
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),

    # Home page
    url(r'^$', 'blogengine.views.getPosts'),
    url(r'^(\d+)/?$', 'blogengine.views.getPosts'),

    # tinyMCE
    (r'^tinymce/', include('tinymce.urls')),

    # Blog posts
    url(r'^\d{4}/\d{1,2}/([-a-zA-Z0-9]+)/?$', 'blogengine.views.getPost'),

    # Categories
    url(r'^categories/(\w+)/?$', 'blogengine.views.getCategory'),
    url(r'^categories/(\w+)/(\d+)/?$', 'blogengine.views.getCategory'),

    # Comments
    #url(r'^comments/', include('django.contrib.comments.urls')),

    # RSS feeds
    url(r'^feeds/posts/$', PostsFeed()),


    # Flat pages
    #url(r'', include('django.contrib.flatpages.urls')),
    #not needed since '...middleware.FlatpageFallbackMiddleware' is installed in settings.py

)

template- sidebar_b.html:

<div class="grid_4 omega">
{% if posts %}
    {% for post in posts %}
            {% if post.featured %}
            <h3>Featured</h3>       

            <div class="featured-post">

                <h4><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h4>
                <p class="post-info">Posted by <a href="index.html">{{ post.author.first_name }} {{ post.author.last_name }}</a> on {{ post.pub_date|date:"m.d.y"  }} </p>
                <p>
                <a href="http://getfirefox.com/"><img src="static/images/image.gif" width="160" height="100" alt="firefox" class="float-left" /></a>

                {{ post.text|safe|truncatechars:200 }}

                </p>    

                <p><a class="more-link" href="{{ post.get_absolute_url }}">continue reading</a></p>

            </div>
            {% endif %}
    {% endfor %}
    {% else %}
    <h3>Featured</h3>
    <div class="featured-post">
        <h4>Nothing to show...</h4>
    </div>
{% endif %}
</div>  

views.py:

from django.shortcuts import render_to_response
from django.core.paginator import Paginator, EmptyPage
from blogengine.models import Post, Category
from django.template import RequestContext
from django.contrib.syndication.views import Feed

from django.template.loader import add_to_builtins
add_to_builtins('blogengine.templatetags.tags')

def getPosts(request, selected_page=1):
    # Get all blog posts
    posts = Post.objects.all().order_by('-pub_date')
    # Add pagination
    pages = Paginator(posts, 5)
    # Get the specified page
    try:
        returned_page = pages.page(selected_page)
    except EmptyPage:
        returned_page = pages.page(pages.num_pages)

    # Display all the posts
    return render_to_response('posts.html', { 'posts':returned_page.object_list, 'page':returned_page}, RequestContext(request))


def getPost(request, postSlug):
    # Get specified post
    post = Post.objects.filter(slug=postSlug)
    # Display specified post
    return render_to_response('single.html', { 'posts':post}, RequestContext(request))

def getCategory(request, categorySlug, selected_page=1):
    # Get specified category
    posts = Post.objects.all().order_by('-pub_date')
    category_posts = []
    for post in posts:
        if post.categories.filter(slug=categorySlug):
            category_posts.append(post)
    # Add pagination
    pages = Paginator(category_posts, 5)
    # Get the category
    category = Category.objects.filter(slug=categorySlug)[0]
    # Get the specified page
    try:
        returned_page = pages.page(selected_page)
    except EmptyPage:
        returned_page = pages.page(pages.num_pages)
    # Display all the posts
    return render_to_response('category.html', { 'posts': returned_page.object_list, 'page': returned_page, 'category': category}, RequestContext(request))

Would it be better practice to create a tag so I could just call {% load posts %} when and where I need it?

  • 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-16T02:50:59+00:00Added an answer on June 16, 2026 at 2:50 am

    i understood the problem as follows:

    flatpages/default.html <= default flatpages template overwrite
       |_ incudes somehow template-sidebar_b.html <= your template
    

    template-sidebar_b.html is included (“called”) by the flatpages-template, but because the flatpage doesnt know a template variable “posts” nothing is rendered.

    possible solutions are:

    • create a templatetag as you said => {% load posts %} => probaby the best solution but only possible if you dont need any filters or stuff in your templatetag you dont have access to in your template because then you have the same problem again.

    • replace the default FlatpageFallbackMiddleware with your own => easy as this and/or look into the code of django.contrib.flatpages.middleware.FlatpageFallbackMiddleware. i think this is the best solution because you have access to the request and response object.

    • add your posts data to a default contextprocessor, the flatpages are rendered with RequestContext (docs) => i do not
      recommend this

    regards

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

Sidebar

Related Questions

I have a Django app that gets it's data completely from an external source
I have a simple class in a Django app called project from django.test import
I have a django app which is used for managing registrations to a survey.
I have a Django app which uses LDAP as the authentication backend. I'm not
I have a Django app which, submitting a package, should return values that are
I have a model called Activity in my django app. in the admin interface,
I have created a permission system in django. It is inside an App called
In my django application I have an app called projects and and app called
I have a model in my dJango app called event . I want users
Suppose I have a Django app named blog. There's a model called Post and

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.