0

Created a tornado template template.html like so:


    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      {% set base = '.' %}
      <link rel="stylesheet" href="style.scss" />
    </head>

And in my gramex.yaml I have


    url:
    ​  endpoint:
        pattern: /$YAMLURL/tmpl/?([^/]*)?/?([0-9]+)?
        handler: FileHandler
        kwargs:
          path: $YAMLPATH/template.html
          template: true

Now running gramex and trying to access the page.

when I access http://localhost:9988/tmpl, IT works fine and the SCSS is linked.
However accessing http://localhost:9988/tmpl/1 or http://localhost:9988/tmpl/1/1 tries to get the SCSS from .../tmp/style.scss and .../tmp/1/style.scss respectivelly. I am sure that I am missing something very small.
Any help will be greatly appreciated.

PS - One solution is to use absolute paths like

<link rel="stylesheet" href="/style.scss" /> However, that is not preferable.

1 Answers1

0

A few possible solutions:

  1. Use static_url
  <link rel="stylesheet" href="{{ static_url('style.css') }}" />

and keep style.scss in <project_root>/static/style.scss

  1. Change base and use it
  {% set base = '/' %}
  <link rel="stylesheet" href="{{ base }}style.css" />

Not sure if those are best practices, but they work.

  • 1
    I generally use approach #2. I find it the simplest. Another option is to count the number of `/` characters in `handler.request.uri` and use `"../" * count` as the prefix. – S Anand Jul 27 '23 at 16:45