How to solve error about Askama?

I'm Rust beginner. I want to compile this file, but i get error.
Because I wrote #[derive(Template)], I think that it should be inheritable.
Am I missing something?

error: unable to parse template:

"{% for entry in entries %}\n      <div>\n        <div>id:{{}}, text: {{entry.text}}</div>\n        <form action=\"/delete\" method=\"POST\">\n          <input type=\"hidden\" name=\"id\" value=\"{{}}\">\n          <button>delete</button>\n        </form>\n      </div>\n      {% end for %}\n    </div>\n    <form action=\"/add\" method=\"POST\">\n      <div>\n        <input nme=\"text\">\n      </div>\n      <div>\n        <button>add</button>\n      </div>\n    </form>\n  </body>\n</html>"
  --> src/
64 | #[derive(Template)]
   |          ^^^^^^^^
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `render` found for struct `IndexTemplate` in the current scope
  --> src/
66 | struct IndexTemplate {
   | -------------------- method `render` not found for this
89 |     let response_body = html.render()?;
   |                              ^^^^^^ method not found in `IndexTemplate`
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `render`, perhaps you need to implement it:
           candidate #1: `Template`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `todo`

use actix_web::{get, App, HttpResponse, HttpServer, ResponseError};
use askama::Template;
use thiserror::Error;

struct TodoEntry {
    id: u32,
    text: String,

#[template(path = "index.html")]
struct IndexTemplate {
    entries: Vec<TodoEntry>,
#[derive(Error, Debug)]
enum MyError {
    #[error("Failed to render HTML")]
    AskamaError(#[from] askama::Error),

impl ResponseError for MyError {}

async fn index() -> Result<HttpResponse, MyError> {
    let mut entries = Vec::new();
    entries.push(TodoEntry {
        id: 1,
        text: "First entry".to_string(),
    entries.push(TodoEntry {
        id: 2,
        text: "Second entry".to_string(),
    let html = IndexTemplate { entries };
    let response_body = html.render()?;

async fn main() -> Result<(), actix_web::Error> {
    HttpServer::new(move || App::new().service(index))


actix-rt = "2.2.0"
actix-web = "3.3.2"
askama = "0.10.5"
thiserror = "1.0.24"

<!DOCTYPE html>
    <meta charset="utf-8" />
    <title>Todo App</title>

      {% for entry in entries %}
        <div>id:{{}}, text: {{entry.text}}</div>
        <form action="/delete" method="POST">
          <input type="hidden" name="id" value="{{}}">
      {% end for %}
    <form action="/add" method="POST">
        <input nme="text">

I think that is the key: there appears to be an error in the Template, as a result, Rust can not automatically derive the render function (which is supposed to be based off of index.html).

Then, it complains about no render function (because the error in index.html prevented it from being created).

Lookin at Template syntax - Askama , I think this should be {% endfor %} (no space between end and for).

1 Like

Thanks to your advice, I can move on coidng!!
I didn't read the documentation well.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.