Code Monkey home page Code Monkey logo

Comments (7)

vallentin avatar vallentin commented on August 23, 2024 1

Duplicate of #383

I explained why it occurs in that issue #383 (comment).

In short, it has to do with how paths are resolved. Your path is actually templates/../../pages/contact.html, so if templates/ doesn't exist, then it fails. This is because on Unix templates might be a symlink, so it has to resolve templates first. If it doesn't exist, then you get an error.

The workaround is that instead of starting your paths with ../, then instead create a askama.toml file and add:

[general]
dirs = ["path/to/pages"]

The dirs path you can use ../ e.g. ../pages. Since here .. is relative to the crate/directory that askama.toml is in, and that directory definitely exists.

from askama.

vallentin avatar vallentin commented on August 23, 2024 1

@djc Yes, I'll look into it. Since I'm already documenting other stuff

from askama.

djc avatar djc commented on August 23, 2024

It is intended to be platform-agnostic, so this might just be a bug? (Could be a bug on the Windows side, though...)

I don't know exactly what's going on here, but maybe have a look at the Config::find_template() code and debug what it's doing with your setup?

from askama.

Necoo33 avatar Necoo33 commented on August 23, 2024

It is intended to be platform-agnostic, so this might just be a bug? (Could be a bug on the Windows side, though...)

I don't know exactly what's going on here, but maybe have a look at the Config::find_template() code and debug what it's doing with your setup?

What happens in windows side is ideal behavior imo. Giving a relative path is way more easy. So i think you should apply this behavior for linux on future versions. Strictly defining folder and place of that folder of the templates is not good for development experience.

from askama.

djc avatar djc commented on August 23, 2024

@vallentin do you think it makes sense for us to document this behavior in the Askama book?

from askama.

vallentin avatar vallentin commented on August 23, 2024

So I was thinking more about this. We could also specialize this case, where the template path starts with ../.

So when resolving the template path, say the path is ../path/to/template and dirs is ["template", "a/b", "c/d"], then they would be tested in this order:

  • [root]/template/../path/to/template
  • [root]/path/to/template
  • [root]/a/b/../path/to/template
  • [root]/a/to/template
  • [root]/c/d/../path/to/template
  • [root]/c/to/template

Testing like this, would ensure that even if someone actually symlinked templates/, thus templates/../path/to/template actually be valid, then we aren't breaking anything.

I just want to point out again, that the/my original issue #383. This issue only exists on Unix and macOS. The behavior works as expected on Windows, given that there's no symlinks to resolve in the first place. Which funnily enough meant that I first triggered the issue myself, when I attempted to build on a separate system.

To be very clear, I'm only suggesting special casing a path starting with ../. I'm not suggesting resolving any other .. in the path. So the implementation should be super simple, e.g. dir.parent() if path starts with Component::ParentDir.


Of course we should still recommend in the book, that people actually use askama.toml and [dirs]. But this seems like something that catches people off-guard. Especially considering that this just works on Windows.


The main question is, should it resolve in the previous order, or this order:

  • [root]/template/../path/to/template
  • [root]/a/b/../path/to/template
  • [root]/c/d/../path/to/template
  • [root]/path/to/template
  • [root]/a/path/to/template
  • [root]/c/path/to/template

What do you think @djc?

from askama.

djc avatar djc commented on August 23, 2024

If the goal is to more closely match the behavior on Windows, we should probably also try to match the order that Windows ends up with?

from askama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.