如何在Flask中从多个个体字典返回具有相似元素的结果

2024-10-06 14:52:41 发布

您现在位置:Python中文网/ 问答频道 /正文

Flask-无法使用Flask模板在多个词典中显示所有结果

下面是我的

应用程序类型

            for item in all_information_technology_jobs:
                jobs = item.find('div', class_='item-featured')
                job_name = (jobs.a)["title"]

                job_links = item.find('div', class_='item-featured')
                job_link = (job_links.a)["href"]

                companies = item.find('span', class_='job-company')
                company = (companies.a.text)

                job_types = item.find('span', class_='job-type')
                job_type = job_types.a.text

                job_locations = item.find('span', class_='job-location')
                job_location = job_locations.a.text

                job_dates = item.find('time', class_='entry-date')
                job_date = job_dates.find_all('span')[1].text

                dict = {'JobName': job_name, 'Organisation': company, 'JobType': job_type, 'JobLocation': job_location,
                        'JobExpiry': job_date[3:], 'JobLink': job_link}

                print(dict) // i use this for debugging 

下面是我的

显示.html

<html>
   <body>
      <table border = 1>
         {% for key, value in result.items() %}
            <tr>
               <th> {{ key }} </th>
               <td> {{ value }} </td>
            </tr>
         {% endfor %}
      </table>
   </body>
</html>

**if i print(dict) - the code outputs all results** 

```{'JobName': 'ICT SUPERVISOR', 'Organisation': 'Médecins Sans Frontières', 'JobType': 'Fixed Term', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 23, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/ict-supervisor-4/'}
{'JobName': 'Senior Network and Communications Admin', 'Organisation': 'UNOPS', 'JobType': 'Fixed Term', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 23, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/senior-network-and-communications-admin/'}
{'JobName': 'Index Case Testing (ICT) officer', 'Organisation': 'Population Services International (PSI)', 'JobType': 'Full Time', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 26, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/index-case-testing-ict-officer/'}
{'JobName': 'Humanitarian Information Management Officer – All Nationalities', 'Organisation': 'Cuso International', 'JobType': 'Full Time', 'JobLocation': 'Ethiopia', 'JobExpiry': 'October 1, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/humanitarian-information-management-officer-all-nationalities/'}
{'JobName': 'Data Quality Analyst', 'Organisation': 'Laterite', 'JobType': 'Full Time', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 18, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/data-quality-analyst-2/'}
{'JobName': 'Teamleader technical implementation wastewater treatment – Sewage Wastewater Treatment Plants, Addis Ababa', 'Organisation': 'GIZ', 'JobType': 'Contract', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 29, 2019\n', 'JobLink```

**but if i use the flask template ..** 

Its only showing the top result only and omitting all other results ...

```{'JobName': 'ICT SUPERVISOR', 'Organisation': 'Médecins Sans Frontières', 'JobType': 'Fixed Term', 'JobLocation': 'Ethiopia', 'JobExpiry': 'July 23, 2019\n', 'JobLink': 'https://ngojobsinafrica.com/job/ict-supervisor-4/'}

如何使flask遍历所有字典结果。。。。就像打印报表一样


Tags: httpscomjobfinditemjulyclassjobname