python - Apache AutoIndex 和 Python PEP 503

标签 python apache mod-autoindex

我正在尝试基于 these instructions 设置一个简单的 Python 存储库.

我已经创建了所需的目录结构,但是 pip找不到任何版本。深入研究该主题并引用 PEP 503 - Simple Repository API 后我发现自动生成的HTML站点的结构应该是:

<!DOCTYPE html>
<html>
  <body>
    <a href="/frob/">frob</a>
    <a href="/spamspamspam/">spamspamspam</a>
  </body>
</html>

同一政治公众人物还说:

The text of the anchor tag MUST be the normalized name of the project and the href attribute MUST link to the URL for that particular project.

就我而言,它看起来像这样:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 </head>
 <body>
<h1>Index of /</h1>
<ul><li><a href="packet_name/"> packet_name/</a></li>
</ul>
</body></html>

注意 <a> 开头的空格和结尾的斜杠标签。这是

<a href="packet_name/"> packet_name/</a>

但应该是

<a href="packet_name/">packet_name</a>

.htaccess 文件当前如下所示:

Options +Indexes
IndexOptions SuppressColumnSorting -FancyIndexing
IndexIgnore ..

有没有办法指示 Apache 按照 PEP 503 的要求提供目录布局?

最佳答案

事实证明,问题不是链接的格式,而是规范化的文件夹结构。 PEP 503 期望根级别的文件夹能够标准化。将该项目的名称视为 foo_bar。那么,目录布局必须是:

.
|- foo-bar
|-- foo_bar-0.1.tar.gz

请注意,通过用单个 - 替换 .、- 或 _ 字符,该文件夹已“标准化”。之后 .htaccess 文件和自动生成的索引就可以正常工作了。

这是 PEP 503 的相关部分:

is PEP references the concept of a "normalized" project name. As per PEP 426 the only valid characters in a name are the ASCII alphabet, ASCII numbers, ., -, and _. The name should be lowercased with all runs of the characters ., -, or _ replaced with a single - character. This can be implemented in Python with the re module:

关于python - Apache AutoIndex 和 Python PEP 503,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091949/

相关文章:

java - 如何在maven的settings.xml中配置无代理?

apache - .htaccess 代码拒绝文件夹浏览

javascript - 编辑 Apache mod_autoindex 以预览图像和 mp3

python - 连接表中的列值 - pandas

python - 当我执行 HttpResponseRedirect (302) 时,Django 登录 POST 挂起

regex - mod_rewrite : How can I rewrite a url with slash?

nginx - 如何强制自动索引并忽略index.html 文件

python - Pyspark - 将多列数据组合成一个跨行分布的列

python - 用字典扩展数据框

php - .htaccess 使用 GET 参数重定向