askama icon indicating copy to clipboard operation
askama copied to clipboard

Could not find `askama_warp` in `{{root}}`

Open Kerollmops opened this issue 3 years ago • 7 comments

Hey @djc,

Thank you for this pretty good crate, unfortunaltely I tried it and I found a little problem, probably related to the recent migration/split of the derive crates.

[dependencies]
askama = { version = "0.10.1", features = ["with-warp"] }
error[E0433]: failed to resolve: could not find `askama_warp` in `{{root}}`
  --> src/bin/serve.rs:36:10
   |
36 | #[derive(Template)]
   |          ^^^^^^^^ could not find `askama_warp` in `{{root}}`
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

I found a way to solve this is issue by using both crates. And importing the askama_warp::Template trait reexport instead of the askama one.

[dependencies]
askama = "0.10.1"
askama_warp = "0.10.0"

Kerollmops avatar Jul 11 '20 10:07 Kerollmops

I think this is intentional; when using an integration, you should just import everything directly from askama_warp. Let me know if you see any issues with that!

djc avatar Jul 11 '20 12:07 djc

So, why the with-warp feature exist at all? I don't use it with the workaround I found.

Is the second solution I use the right way to use askama with warp?

Kerollmops avatar Jul 11 '20 13:07 Kerollmops

The feature exists only so that askama_warp can depend directly on askama, which has to enable the feature inside askama_derive which writes out the warp specific generated code. The second solution seems right, except you shouldn't also be relying on askama directly IMO.

djc avatar Jul 11 '20 18:07 djc

If I only have the askama_warp crate in the dependencies I got this error. This is one of the reason I find it a little bit confusing, the other reason is that in the book the with-warp feature on the askama is recomended.

error[E0433]: failed to resolve: could not find `askama` in `{{root}}`
  --> src/bin/serve.rs:37:10
   |
37 | #[derive(Template)]
   |          ^^^^^^^^ could not find `askama` in `{{root}}`
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Kerollmops avatar Jul 11 '20 21:07 Kerollmops

Hmm, the book is probably just out of date in this regard. Would you mind giving me the expanded code from your example code (by attaching print = "code" to the template() attribute, or just using cargo expand for it?

djc avatar Jul 13 '20 09:07 djc

Here is the generated code.
impl ::askama::Template for IndexTemplate {
  fn render_into(&self, writer: &mut ::std::fmt::Write) -> ::askama::Result<()> {
      include_bytes !
("/Users/clementrenault/Documents/mega-mini-indexer/templates/index.html") ;
      write!(
          writer,
          "<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <link rel=\"stylesheet\" href=\"/bulma.min.css\">\n  <link rel=\"stylesheet\" href=\"/style.css\">\n  <script type=\"text/javascript\" src=\"/jquery-3.4.1.min.js\"></script>\n  <script type=\"text/javascript\" src=\"/papaparse.min.js\"></script>\n  <script type=\"text/javascript\" src=\"/filesize.min.js\"></script>\n  <title>{expr0} | The milli engine</title>\n</head>\n<body>\n\n  <section class=\"hero is-light\">\n    <div class=\"hero-body\">\n      <div class=\"container\">\n        <h1 class=\"title has-text-centered\">\n          Welcome to milli\n        </h1>\n        <nav class=\"level\">\n          <div class=\"level-item has-text-centered\">\n            <div>\n              <p class=\"heading\">Database Name</p>\n              <p class=\"title\">{expr0}</p>\n            </div>\n          </div>\n          <div class=\"level-item has-text-centered\">\n            <div>\n              <p class=\"heading\">Database Size</p>\n              <p class=\"title\" id=\"db-size\">{expr1}</p>\n            </div>\n          </div>\n          <div class=\"level-item has-text-centered\">\n            <div>\n              <p class=\"heading\">Number of Documents</p>\n              <p class=\"title\" id=\"docs-count\">{expr2}</p>\n            </div>\n          </div>\n        </nav>\n      </div>\n    </div>\n  </section>\n\n  <section class=\"hero container\">\n    <div class=\"notification\" style=\"border-radius: 0 0 4px 4px;\">\n\n      <nav class=\"level\">\n        <!-- Left side -->\n        <div class=\"level-left\">\n          <div class=\"level-item\">\n            <div class=\"field has-addons has-addons-right\">\n              <input id=\"search\" class=\"input\" type=\"text\" autofocus placeholder=\"e.g. George Clooney\">\n            </div>\n          </div>\n          <div class=\"level-item\"></div>\n        </div>\n\n        <!-- Right side -->\n        <nav class=\"level-right\">\n          <div class=\"level-item has-text-centered\">\n            <div>\n              <p class=\"heading\">Documents</p>\n              <p id=\"count\" class=\"title\">0</p>\n            </div>\n          </div>\n          <div class=\"level-item has-text-centered\">\n            <div>\n              <p class=\"heading\">Time Spent</p>\n              <p id=\"time\" class=\"title\">0ms</p>\n            </div>\n          </div>\n        </nav>\n      </nav>\n\n    </div>\n  </section>\n\n  <section>\n    <ol id=\"results\" class=\"content\">\n      <!-- documents matching requests -->\n    </ol>\n  </section>\n</body>\n\n<script type=\"text/javascript\" src=\"/script.js\"></script>\n\n</html>",
          expr0 = &::askama::MarkupDisplay::new_unsafe(&self.db_name, ::askama::Html),
          expr1 = &::askama::MarkupDisplay::new_unsafe(&self.db_size, ::askama::Html),
          expr2 = &::askama::MarkupDisplay::new_unsafe(&self.docs_count, ::askama::Html),
      )?;
      Ok(())
  }
  fn extension(&self) -> Option<&'static str> {
      Some("html")
  }
  fn size_hint(&self) -> usize {
      2556
  }
}
impl ::askama::SizedTemplate for IndexTemplate {
  fn size_hint() -> usize {
      2556
  }
  fn extension() -> Option<&'static str> {
      Some("html")
  }
}
impl ::std::fmt::Display for IndexTemplate {
  fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
      ::askama::Template::render_into(self, f).map_err(|_| ::std::fmt::Error {})
  }
}
impl ::askama_warp::warp::reply::Reply for IndexTemplate {
  fn into_response(self) -> ::askama_warp::warp::reply::Response {
      ::askama_warp::reply(&self, "html")
  }
}

Kerollmops avatar Jul 13 '20 17:07 Kerollmops

Ah yeah, I think the additivity of feature flags makes it challenging to only have one import, unfortunately. So I think you should probably just keep the workaround as is.

djc avatar Jul 13 '20 20:07 djc