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: NfRQr9R.jpg]
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: NfRQr9R.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Browser won't parse text from yaml loaded into Jinja SpongeB0B 1 952 Jul-07-2022, 09:37 PM
Last Post: SpongeB0B
Question Accessing a value of a dictionary with jinja.... SpongeB0B 2 10,321 Aug-06-2021, 09:05 AM
Last Post: ndc85430
  Flask Basics request.form ifigazsi 0 1,783 Feb-09-2021, 09:05 AM
Last Post: ifigazsi
  Flask request.form ifigazsi 2 3,569 Feb-02-2021, 11:56 AM
Last Post: buran
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,135 Jan-09-2021, 06:08 PM
Last Post: eraosa
  POST request with form data issue web scraping hoff1022 1 2,649 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 2,735 May-01-2020, 05:50 PM
Last Post: Larz60+
  Pre-populating WTForms form values for edit danfoster 0 2,349 Feb-25-2020, 01:37 PM
Last Post: danfoster
  Flask tutorial errors in jinja, auth undefined Ecniv 2 2,451 May-03-2019, 02:04 PM
Last Post: Ecniv
  flask sqlite jinja accessing and updating database help pascale 5 4,080 Feb-11-2019, 03:49 PM
Last Post: pascale

Forum Jump:

User Panel Messages

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