eugeneyan / eugeneyan-comments

1 stars 1 forks source link

https://eugeneyan.com/writing/how-to-set-up-html-app-with-fastapi-jinja-forms-templates/ #10

Open eugeneyan opened 4 years ago

eugeneyan commented 4 years ago

Migrated from json into utteranc.es

eugeneyan commented 4 years ago

Hi Eugene, thanks a lot for this informative article!

From what I've read (e.g. this article), the advantages of FastAPI over Flask are speed, native async support and auto API documentation.

For building web apps, FastAPI's concise syntax and its documentation is certainly a plus, but Flask is well-proven, has a large community, number of available tutorials, Stack Overflow threads.

So, currently, I'd use FastAPI for building REST APIs and Flask for creating web apps (however I only have experience with the latter). Given your experience with FastAPI, which framework would you choose for which task?

Best wishes, Dominik

Comment by Dominik Haitz on 2020-07-27T14:12:54Z

eugeneyan commented 4 years ago

Hey Dominik, thanks for sharing the comparison. Similarly, I've only had experience with Flask but decided to build my new (web) app on FastAPI.

So far, FastAPI has what I need (i.e., templates, jinja2, forms, serve); thus functionality is not an issue. The syntax is also simple and minimal. Nonetheless, as you mentioned, there are fewer tutorials and questions posted on SO (though it's growing daily).

My apps are mostly demos of machine learning prototypes and FastAPI meets my requirements (so far). Thus, I'll be switching fully to FastAPI for both REST and web. If I come across any blockers (i.e., missing functionality, bugs), I'll report them here.

Comment by Eugene Yan on 2020-07-27T14:50:42Z

eugeneyan commented 4 years ago

great, thanks for your answer! :-)

Comment by Dominik Haitz on 2020-07-28T12:03:34Z

RickBL99 commented 3 years ago

Just learning, but don't you need to have Jinja variable in the HTML for the result to show after POST? (

Result: {{result}}

). Might be totally missing something here. How does the result variable end up being presented in the HTML?

eugeneyan commented 3 years ago

Great catch @RickBL99!

The {{ result }} wasn't showing up in the Jekyll markdown code block.

Have fixed it by escaping it like so:

{% raw %}
<p>Result: {{ result }}</p>
{% endraw %}

You can find the HTML for the form here, together with the full repo.

swartchris8 commented 3 years ago

I haven't come across the ellipsis operator before what does it do in Form(...) how would this be structured in older python?

eugeneyan commented 3 years ago

FastAPI understands the ellipsis in Form(...) to mean that the parameter is required. If the ellipsis isn't available, I think None can be used as well but it wouldn't enforce the argument requirement.

Other uses of ... include array slicing and as a no-op placeholder.

bugindia2009 commented 8 months ago

Dear Sir,

I am trying to post html form data using fastapi using python.

Below is my public git repository.

https://github.com/bugindia2009/fapigithub

When I click on the submit button, I received an error Unprocessable Entity.

Please advise.