回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>这是我的第一篇文章,我刚刚开始学习python和django。我成功地连接到了一个公共(非认证)API。当我显示结果时-我可以访问所有字段,但是其中一个字段作为列表返回-<b>其他角色</b>。我可以显示整个列表(无格式),逗号分隔-但我不知道如何迭代列表并将其呈现为<code><ul></code>。你知道吗</p>
<p>返回的列表如下所示:</p>
<pre>
SOC: 3112
Title: Electrical and electronics technicians
Description: Electrical and electronics technicians perform a variety of miscellaneous technical support functions to assist with the design, development, installation, operation and maintenance of electrical and electronic systems.
Qualifications: Entrants usually possess GCSEs/S grades, an Intermediate GNVQ/GSVQ Level II or a BTEC/ SQA award. NVQs/SVQs in Servicing Electronic Systems are available at Levels 2 and 3.
Tasks: plans and prepares work and test schedules based on specifications and drawings; sets up equipment, undertakes tests, takes readings, performs calculations and records and interprets data; plans installation methods, checks completed installation for safety and controls or undertakes the initial running of the new electrical or electronic equipment or system; diagnoses and detects faults and implements procedures to maintain efficient operation of systems and equipment; visits and advises clients on the use and servicing of electrical and electronic systems and equipment.
Other roles: ['Assistant, electronics', 'Engineer, executive (telecommunications)', 'Technician, electronics', 'Officer, signals (MOD)', 'Specialist, telecommunications', 'Technician, electrical', 'Engineer, assistant (broadcasting)', 'Engineer, simulator, flight', 'Technician, telemetry', 'Engineer, testing, cable, assistant', 'Technician, maintenance, electrical', 'Technician', 'Technician, avionics', 'Engineer, installation (electricity supplier)']</pre>
<p>我一直在关注:<a href="https://simpleisbetterthancomplex.com/tutorial/2018/02/03/how-to-use-restful-apis-with-django.html" rel="nofollow noreferrer">https://simpleisbetterthancomplex.com/tutorial/2018/02/03/how-to-use-restful-apis-with-django.html</a>并尽可能多地浏览,以帮助我更好地理解如何访问列表元素并对其进行迭代。你知道吗</p>
<p>html模板呈现上述内容:</p>
<pre><code> {% if search_result.success %}
<p>
<strong>SOC:</strong> {{ search_result.soc }}
<br />
<strong>Title:</strong> {{ search_result.title }}
<br />
<strong>Description:</strong> {{ search_result.description }}
<br />
<strong>Qualifications:</strong> {{ search_result.qualifications }}
<br />
<strong>Tasks:</strong> {{ search_result.tasks }}
<br />
<strong>Other roles:</strong> {{ search_result.add_titles }}
</p>
{% else %}
<p><em>{{ search_result.message }}</em></p>
{% endif %}
</code></pre>
<p>试图进入决赛</p>
<pre><code>{{ search_reults.add_titles }}
</code></pre>
<p>在项目符号列表中,我尝试了几种不同的选项,包括:</p>
<pre><code> <ul>
{% for title in search_result.add_titles %}
<li>{{ title }}</li>
{% endfor %}
</ul>
</code></pre>
<p>我希望把清单变成这样:</p>
<ul>
<li>电子助理</li>
<li>工程师、主管(电信)</li>
<li>电子技术员</li>
<li>信号官(国防部)</li>
<li>电信专家</li>
<li>电气技术员</li>
<li>工程师、助理(广播)</li>
<li>工程师,模拟器,飞行</li>
<li>遥测技术员</li>
<li>工程师、测试、电缆、助理</li>
<li>电气维修技师</li>
<li>技术员</li>
<li>航空电子技术员</li>
<li>安装工程师(电力供应商)</li>
</ul>
<p>任何帮助将不胜感激-希望是新手的错误?你知道吗</p>
<p>编辑:</p>
<p>电流视图.py地址:</p>
<pre><code>def lmi4all(request):
search_result = {}
if 'SOC' in request.GET:
soc = request.GET['SOC']
url = 'http://api.lmiforall.org.uk/api/v1/soc/code/%s' % soc
response = requests.get(url)
search_was_successful = (response.status_code == 200) # 200 = SUCCESS
search_result = response.json()
search_result['success'] = search_was_successful
return render(request, 'core/lmi4all.html', {'search_result': search_result})
</code></pre>