tags:

views:

19

answers:

1

So I'm writing a basic feed aggregator/popurls clone site in Django and having trouble getting the feeds to update.

For each feed source, I have a separate app to parse and return the requested info, for the sake of simplicity let's say it's just getting the feed title. eg:

#feed source xyz views.py
from django.http import HttpResponse
import feedparser

def get_feed_xyz():
    xyz_feed = "http://www.xyz.com/feed.xml"
    feed = feedparser.parse(xyz_feed)

    info = []
    for entry in feed.entries:
        info.append(entry.title)
    return info

I then have an aggregator app that aggregates all the links.

#aggregator views.py
from django.shortcuts import render_to_response
from site.source.views import get_feed_xyz
#etc 

aggregate = get_feed_xyz() # + other feeds etc

def index(request):
    return render_to_response('template.html',{'aggregate' : aggregate})

My problem is in updating the feeds... they will not update unless I restart Apache! I've tried make a feed_update.py that runs the get_feed_xyz() command, but the site still doesn't update. I think I'm missing some essential part of how Django works here, because I simply can't figure it out.

A: 

aggregate is a global variable, so the function get_feed_xyz() is only called when the module loads. You will need to update it inside index().

phsiao
So moving aggregate = get_feed_xyz() # + other feeds etc to the index() function should do the trick?
Tony
Based on my understanding of the code, yes.
phsiao