Code Monkey home page Code Monkey logo

Comments (4)

Kijewski avatar Kijewski commented on August 23, 2024

Could you please copy the exact output of the compiler? In my superficial test the code compiled fine in both the last released version and the current development version.

from askama.

KaiyuanMa avatar KaiyuanMa commented on August 23, 2024

Could you please copy the exact output of the compiler? In my superficial test the code compiled fine in both the last released version and the current development version.

I am using the input component like this,

{%- import "components/input.html" as input -%}
{% extends "base.html" %}


{% block content %}
  {% call input::input(None, None, None) %}
  {% call input::input(None, None, None) %}
{% endblock %}

I get red underline in the Template derive in the struct

#[derive(Default, Template)]
#[template(path = "routes/login.html")]
pub struct Login<'a> {
    pub email_error_msg: &'a str,
    pub form_error_msg: &'a str,
}

type annotations needed
cannot infer typerustc[Click for full compiler diagnostic]
askama_derive
proc_macro Template

When I cargo run i get this error

error[E0282]: type annotations needed
  --> src/templates.rs:22:19
   |
22 | #[derive(Default, Template)]
   |                   ^^^^^^^^ cannot infer type
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

but when I change both input back to input(Some("email"), Some("email"), Some(true)) all errors go away
I am using version 0.12.0

from askama.

KaiyuanMa avatar KaiyuanMa commented on August 23, 2024

Update:
I must have done something wrong, or the original code is just too messy. Anyway here is the updated and working version.

{% macro input(input_name, input_type, input_required) %}
    <input
        name="{{input_name.unwrap_or("")}}"
        type="{{input_type.unwrap_or("")}}"
        required="{{input_required.unwrap_or(false)}}"
        class="rounded h-[1.8em] px-2 mb-2 mt-1 text-sm"
    />
{% endmacro %}

from askama.

jh9aea avatar jh9aea commented on August 23, 2024

I have the same issue

  {% macro all(items) %}
  {% for item in items.unwrap() if items.is_some() %}
    <div>{{ item.name }}</div>
  {% endfor %}
  {% endmacro %}
{% import("items.html") as items %}
{% call  items::all(None) %}
error[E0282]: type annotations needed
  --> main/src/main.rs:28:10
   |
28 | #[derive(Template)]
   |          ^^^^^^^^ cannot infer type
   |
   = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
// unfortunately i can`t do this
{% import("items.html") as items %}
{% call items::all(None::<crate::Item>) %}
// or this
{% macro all(items: Option<Vec<crate::Item>>) %}...

so i don`t know how to solve this problem
mb you could advise me something?

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.