Re: Can't display data from app in flatpages

20 views
Skip to first unread message

Jason Arnst-Goodrich

unread,
Dec 20, 2012, 5:07:15 PM12/20/12
to django...@googlegroups.com
The flatpages view is not provided the context which includes 'posts'.

IMO you are correct with the {% load posts %} technique because it is entirely as result of the template you are using that requires you display that information -- if that makes sense.

In other words it's not because of the flatpage you are loading but rather the template you are using which necessitates the 'posts' being used.

On Wednesday, December 19, 2012 8:40:21 PM UTC-8, Frank Valcarcel wrote:
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

)

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

I can call them up by normal means by using  {% if posts %}...{% for post in posts %}  but trying to use this in flatpages that call the same template section of the page displays nothing. Any ideas?

Reply all
Reply to author
Forward
0 new messages