Python Forum
Jinja sort values from request.form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jinja sort values from request.form
#1
Hi everyone,

I'm following this tutorial -> https://www.tutorialspoint.com/flask/fla...mplate.htm

I tried to have the value sorted in the result.html

I tried many way in result.html as in the .py file. nothing work.

In python I'm accustomed to use
sorted(mydict)
but here it's not working any ideas how to solve this ?
[Image: S3maEis.png]
Reply
#2
Templates shouldn't have any logic in them really. Sort the data in your handler and pass it yo the template. What problem are you having in doing that?
Reply
#3
Nevermind,

I found the problem when I was using sorted() it returned a list an jinja (or flask) didn't like that.

so now in the .py file I use this ->

import collection
...
def result():
   if request.method == 'POST':
      collect = request.form
      return render_template("result.html",result= collections.OrderedDict(sorted(result.items())))
[Image: S3maEis.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Accessing a value of a dictionary with jinja.... SpongeB0B 2 352 Aug-06-2021, 09:05 AM
Last Post: ndc85430
  Flask Basics request.form ifigazsi 0 613 Feb-09-2021, 09:05 AM
Last Post: ifigazsi
  Flask request.form ifigazsi 2 617 Feb-02-2021, 11:56 AM
Last Post: buran
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 986 Jan-09-2021, 06:08 PM
Last Post: eraosa
  POST request with form data issue web scraping hoff1022 1 1,216 Aug-14-2020, 10:25 AM
Last Post: kashcode
  how to create dynamic arguments to be passed in jinja template in url_for function? experimental 1 1,070 May-01-2020, 05:50 PM
Last Post: Larz60+
  Pre-populating WTForms form values for edit danfoster 0 792 Feb-25-2020, 01:37 PM
Last Post: danfoster
  Flask tutorial errors in jinja, auth undefined Ecniv 2 1,106 May-03-2019, 02:04 PM
Last Post: Ecniv
  flask sqlite jinja accessing and updating database help pascale 5 1,862 Feb-11-2019, 03:49 PM
Last Post: pascale
  display multiple sensors on webpage python flask jinja pascale 6 2,623 Jan-29-2019, 10:10 AM
Last Post: pascale

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020