Thanks so much for your help. I'm sorry to ask another question, but I am getting an error and have spent a few hours trying to figure it out. Googling has not helped me.
Environment: Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.1.1 Python Version: 2.6.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'discvideos.videos'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/Users/matt/Sites/discvideos/../discvideos/videos/views.py" in home_page 21. tree = ET.parse(feed) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ xml/etree/ElementTree.py" in parse 862. tree.parse(source, parser) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ xml/etree/ElementTree.py" in parse 586. parser.feed(data) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ xml/etree/ElementTree.py" in feed 1245. self._parser.Parse(data, 0) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ xml/etree/ElementTree.py" in _default 1201. self._parser.ErrorColumnNumber) Exception Type: ExpatError at / Exception Value: undefined entity …: line 198, column 55 Here is my home_page: http://utilitybase.com/paste/23116 http://diveintopython3.org/xml.html seems to be explaining the problem but I haven't gotten the code there to work for me yet. Thank you. On Dec 5, 11:40 pm, Sam Lai <[email protected]> wrote: > Inline. > > 2009/12/6 sleepjunk <[email protected]>: > > > Thank you for the response. I don't believe I explained well enough > > exactly what I'm trying to do. > > > I have table Video with a field vimeo_code. Each vimeo_code has its > > own XML file. The XML file I used in my views.py is just a random > > video I saw on vimeo. I need to replace the vimeo_code so the XML file > > I'm parsing looks likehttp://vimeo.com/api/v2/video/vimeo_code.xml > > Ok, so just replace this line: > > feed = > urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml") > > with, > > feed = > urllib.urlopen("http://vimeo.com/api/v2/video/%s.xml" % v.vimeo_code) > > This replaces the code in the URL with the current vimeo_code in the loop. > > I think we're on the same page; give it a shot and see how it goes. > > > Would it be a better idea to do this as a tag filter? Any additional > > information for me if I do it that way? > > I'm sure someone will have a more concrete reason for doing it one way > or the other. Personally though, it's a matter of style. I prefer > having it in the view function because then I can see immediately that > extra http calls will be made when looking through my code. If I used > a tag filter, I would have to look at the view function to find the > template, then the template to see if custom tag filters were used, > then the .py files for the tag filters to see what it's doing. > > Tag filters are pretty simple things; the Django docs link I gave > should be easy enough. Feel free to post questions if you get stuck > though. > > > Thanks again, I appreciate your help. > > Matt > > > On Dec 5, 10:07 pm, Sam Lai <[email protected]> wrote: > >> See inline. > > >> 2009/12/6 sleepjunk <[email protected]>: > > >> > Hello :) I am working on a small video site that allows a user to add > >> > a video to the site by submitting a Vimeo.com or Youtube.com URL. I'm > >> > trying to display thumbnails without hosting them. For Vimeo videos I > >> > need to parse an XML file to find the thumbnail location. > > >> > On my homepage I would like to display the 5 newest videos. As of now > >> > I'm displaying every video in the database on the homepage. Each video > >> > will have a different thumbnail and XML file to parse. As of right now > >> > my "main_page" in my views.py file looks like this: > > >> > def home_page(request): > >> > template = get_template('home_page.html') > >> > videos = Video.objects.all() > > >> videos_context = [ ] > >> for v in videos:> feed = > >> urllib.urlopen("http://vimeo.com/api/v2/video/7875440.xml") > >> > tree = ET.parse(feed) > >> > root = tree.getroot() > >> > vimeo_thumbnail = root.findtext("video/thumbnail_medium") > > >> videos_context.append( { 'video' : v, 'thumbnail_url' : > >> vimeo_thumbnail } ) > > >> > variables = Context({ > >> > 'videos' : videos_context, > >> > }) > >> > output = template.render(variables) > >> > return HttpResponse(output) > > >> > How can I parse a different XML file for every video? Thank you much. > >> > Again, I am new and could be going about this completely wrong and > >> > gladly accept any feedback you have. > > >> You could try something like the modified view above. It loops through > >> every video, gets the thumbnail URL, creates an object containing the > >> video model instance and the thumbnail URL, and adds it to the list > >> videos_context. > > >> You could then access them in your template like this (assuming > >> there's a name field in your Video model): > > >> {% for v in videos %} > >> <img src="{{v.thumbnail_url}}">{{ v.video.name }} > >> {% endfor %} > > >> The alternate way of doing this is to make a tag filter, > >> seehttp://docs.djangoproject.com/en/dev/howto/custom-template-tags/ > > >> HTH, > > >> Sam > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

