Google App Engine 使用 Python 动态生成站点地图
我有一个网站,我想为其创建动态站点地图。我将 Google App Engine 与 Python 和 Django 结合使用。
我使用 PHP 开发了另一个网站,并且由于我在 Apache 服务器的 .htaccess 上编写的重写规则,可以访问 sitemap.xml。
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
.xml 文件是这样生成的:
$sql_select ="从 livros l 中选择标题、标题、data_insercao 按标题 ASC 排序";
对于我的情况,是否有任何选项(GAE + Python),以便当访问 www.mydomain.com/sitemap.xml 时,他将从服务器收到一个 .xml 文件,其中包含使用 python 生成的动态内容?
$结果 = mysql_query($sql_select) 或 die(mysql_error());
while($row = mysql_fetch_array($result)) {
$titulo = $row['titulo'];
$title = $row['title'];
$data = $row['data_insercao'];
$sql_comentario ="从注释中选择数据 WHERE livros_title = '" 。 $标题。 "' 按数据描述 LIMIT 0 , 1 排序";
$result_comentario = mysql_query($sql_comentario) 或 die(mysql_error());
$row_comentario = mysql_fetch_array($result_comentario);
if($row_commentario){
$data = $row_commentario['data'];
}
$pieces = Explode(" ", $data);
$data = $pieces[0];
$url_product = 'http://www.sinopsedolivro.net/livro/' . $标题。 '.html';
回声
' <网址>
<优先级>0.8
';
}
I have a website and I want to create a dynamic sitemap for it. I use Google App Engine with Python and Django.
I developed another website using PHP and the sitemap.xml was accessable because of this Rewrite Rule I wrote on the .htaccess of the Apache Server.
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
The .xml file was generated like this:
$sql_select ="SELECT titulo, title, data_insercao FROM livros l ORDER BY titulo ASC";
$result = mysql_query($sql_select) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$titulo = $row['titulo'];
$title = $row['title'];
$data = $row['data_insercao'];
$sql_comentario ="SELECT data FROM comentarios WHERE livros_title = '" . $title . "' order by data desc LIMIT 0 , 1";
$result_comentario = mysql_query($sql_comentario) or die(mysql_error());
$row_comentario = mysql_fetch_array($result_comentario);
if($row_comentario){
$data = $row_comentario['data'];
}
$pieces = explode(" ", $data);
$data = $pieces[0];
$url_product = 'http://www.sinopsedolivro.net/livro/' . $title . '.html';
echo
' <url>
<loc>'.$url_product.'</loc>
<lastmod>'.$data.'</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
';
}
Is there any option for my case (GAE + Python) so when one access www.mydomain.com/sitemap.xml, he will receive from the server a .xml file with the dynamicaly content generate myself using python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是尼克·约翰逊在站点地图上写的一篇很棒的文章
站点地图
文章描述了使用部署后方法生成站点地图,另一种方法是偶尔生成站点地图;例如,
如果您将站点地图存储在数据存储中,那么访问速度会非常快,这会影响您的 SEO 排名。
我建议您将站点地图存储在 Nick Johnson 提供的模型中,例如
This is a great article by Nick Johnson on sitemaps
Sitemaps
The article describes using a post deploy method of generating the sitemap, an alternative is to generate the sitemap once in a while; say once a day using cron e.g.
If you store the sitemap within the data store then access will be very fast which impacts your SEO rankings.
I suggest you store the sitemap in a model such as that provided by Nick Johnson e.g.
当然,您可以通过应用程序对任何 url 提供任何您想要的响应。只需将控制器映射到 /sitemap.xml 并在其中编写输出 xml 的代码即可。不要忘记将响应的 mime 类型设置为正确的值。
如果您使用 django,您可能需要阅读 http://docs.djangoproject .com/en/dev/topics/http/urls/
Sure, you can provide any response you want to any url with your application. Just map your controller to /sitemap.xml and write the code that outputs your xml in there. Don't forget to set the mime type of the response to the right value.
If you are using django, you might want to read http://docs.djangoproject.com/en/dev/topics/http/urls/
我遇到了同样的问题,并用 python 构建了一个库来动态生成站点地图,并一直在使用它。
用法:
更多信息请参见此处,github 上的项目链接: https://github.com/cxmcc/sitemap-蟒蛇
I faced the same problem and built a library in python to dynamically generate sitemaps and have been using it since.
Usage:
More info here on, project link on github: https://github.com/cxmcc/sitemap-python