Bottom Page

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 ?
İmage
Quote
#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?
Quote
#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())))
İmage
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how to create dynamic arguments to be passed in jinja template in url_for function? experimental 1 499 May-01-2020, 05:50 PM
Last Post: Larz60+
  POST request with form data issue web scraping hoff1022 0 385 Apr-12-2020, 03:22 PM
Last Post: hoff1022
  Pre-populating WTForms form values for edit danfoster 0 293 Feb-25-2020, 01:37 PM
Last Post: danfoster
  Flask tutorial errors in jinja, auth undefined Ecniv 2 562 May-03-2019, 02:04 PM
Last Post: Ecniv
  flask sqlite jinja accessing and updating database help pascale 5 989 Feb-11-2019, 03:49 PM
Last Post: pascale
  display multiple sensors on webpage python flask jinja pascale 6 1,440 Jan-29-2019, 10:10 AM
Last Post: pascale
  request.form[ Dynamic Value]. How to? KirkmanJ 0 780 Aug-01-2018, 12:14 PM
Last Post: KirkmanJ
  Passing Web Form Values VSPythonD3v 8 2,737 Mar-26-2017, 07:01 PM
Last Post: VSPythonD3v

Forum Jump:


Users browsing this thread: 1 Guest(s)