[Flask] Build a drop down from dictionary

Corey Boyle coreybrett at gmail.com
Mon Aug 5 14:28:47 EDT 2019


depends if you are in Py2 or Py3

https://stackoverflow.com/questions/13998492/when-should-iteritems-be-used-instead-of-items

https://jinja.palletsprojects.com/en/2.10.x/templates/#for

Is the dict created as a literal, or generated dynamically?

Using a tuple/list of tuples/lists might be easier.

On Mon, Aug 5, 2019 at 10:51 AM Ben Duncan <linux4ms at gmail.com> wrote:

> Forgive my ignorance, still trying to learn this stuff.
>
> I have the following test code:
>
> Template:
>
> <div class="dropdown" >
>   <button class="dropbtn">Dropdown 4</button>
>   <div class="dropdown-content">
>     <a href="#">Link 1</a>
>     <a href="#">Link 2</a>
>     <a href="#">Link 3</a>
>     <a href="#">Link 4</a>
>     <a href="#">Link 5</a>
>     <a href="#">Link 6</a>
>   </div>
> </div>
>
> I have a dictionary like:
> { "First Link": "https:/.....etc...", "Second Link": "https:/....", "third
> Link:": "https:....." (and so on ... }
>
> I would like to replace the <a stuff where "link" shows the "key" and the
> href shows the
> URL. How do I go about doing this ?
>
> Thanks ...
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20190805/74b545b9/attachment-0001.html>


More information about the Flask mailing list