Django - 解析XML,输出为iFrame的HTML片段? [英] Django - Parse XML, output as HTML fragments for iFrame?

查看:159
本文介绍了Django - 解析XML,输出为iFrame的HTML片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求快速组合一个采用Yahoo XML Feed的小型系统,解析它,并根据它创建一个HTML片段。



在那一刻,我正在使用Django处理URL路由,使用一些Python脚本,并输出一些HTML(具有硬编码的维度作为内联CSS),可以将其放入iframe中(这部分是我的一半b)b
$ b我还被要求抛出一些其他的东西来解析Twitter XML feed,Wordpress XML搜索结果等,可以重新排列在iFrames的页面上。



URL将像 http://foobar.com/yahoofeed/keyword/dimensions ,或/ twitter / keyword / dimensions,其中,关键字是搜索关键字,确定的分数(我想如果有更多的参数,我应该传递这些作为查询字符串,相反作为URL的一部分的虚拟子项目对吧?思考?优点/缺点?)。



但是,我想知道这是否是最好的方法?对我来说似乎有点黑客,但我并不确定。目前的做法有什么问题吗?



干杯,
维克多

解决方案

您的解决方案听起来不错。你的问题的本质就是将某些位粘合在一起,所以它永远是一个特别的和黑客(Python是最适合这样的工作)。



我将使用查询字符串来执行以下任何操作:




  • 不代表永久资源

  • 表示某种查询或输入选项

  • 表示输出选项



我会这是一个例外,为简单的情况提供不错的URL,如果一直需要一个选项(总是需要),那么你可以使它成为路径的一部分。所以我认为将关键字作为URL的一部分是正确的,但维度应该是查询字符串选项。


I've been asked to quickly put together a small system that takes a Yahoo XML feed, parses it, and creates a HTML fragment based on it.

At the moment, I'm using Django to handle the URL routing, with some Python script, and outputting a bit of HTML in a (with hardcoded dimensions as inline CSS), that can hopefully be put into an iframe (this part was my half-baked idea).

I've also been asked to throw in a few other bits, like something to parse Twitter XML feeds, Wordpress XML search results etc., that could be re-arranged on a page in iFrames as well.

URLs would be somehting like http://foobar.com/yahoofeed/keyword/dimensions, or /twitter/keyword/dimensions,where keyword is the search keyword, and dimensions is one of some pre-determined sizings (I suppose if there more parameters, I should be passing these as query strings, as opposed to as virtual subiddirectories as part of the URL, right? Thoughts? Pros/Cons of either?).

However, I'm wondering if this is the best way to do this? It does seem a bit hackish to me, but I'm not really sure. Are there any problems with the current approach?

Cheers, Victor

解决方案

Your solution sounds fine. The nature of your problem is glueing together some bits, so it will always be a bit ad-hoc and hackish (and Python is ideally suited for a job like that).

I would use query strings for anything which:

  • doesn't represent a permanent resource
  • represents some kind of query or input option
  • represents an output option

I'd make an exception to this to provide nice URLs for the simple case, and if an option was always required (and always will be required) then you could make it part of the path. So I think keeping the keyword as part of the URL is fine, but dimensions should be a query string option.

这篇关于Django - 解析XML,输出为iFrame的HTML片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆