Reputation: 187
I am trying to create a Gramex
application. The intention is to:
readme.md
page when I access localhost:9988
(local gramex
generic port)readme.md
in subdir1
when I access localhost:9988/subdir1/
readme.md
in subdir2
when I access localhost:9988/subdir2/
For that I have a gramex.yaml
file, that reads
url:
app:
pattern: /$YAMLURL/
handler: FileHandler
kwargs:
index: false
path:
"": $YAMLPATH/{dir}/readme.md
transform:
"*.md":
encoding: utf-8
function: markdown.markdown(content)
headers:
Content-Type: text/html; charset=UTF-8
default:
dir: ""
file: readme
ext: md
Here localhost:9988
renders the root folder readme.md
.
However, browsing localhost:9988:subdir1
renders the directory index, implying that subdirs
are not working.
Wondering if this is possible or not.
Upvotes: 1
Views: 18
Reputation: 11948
You need to change 3 things:
pattern: /$YAMLURL/
should be pattern: /$YAMLURL/.*
. Otherwise, no other URL will matchpath: "": $YAMLPATH/{dir}/readme.md
is not requireddefault:
is not a kwarg. Use default_filename: readme.md
Here's a working configuration:
url:
app:
pattern: /$YAMLURL/(.*)
handler: FileHandler
kwargs:
path: $YAMLPATH
default_filename: README.md
transform:
"*.md":
encoding: utf-8
function: markdown.markdown(content)
headers:
Content-Type: text/html; charset=UTF-8
The documentation is at https://gramener.com/gramex/guide/filehandler/
Upvotes: 0