第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

通過其他循環(huán)循環(huán)

通過其他循環(huán)循環(huán)

慕慕森 2022-08-25 13:39:05
循環(huán)通過其他循環(huán),我正在嘗試從上下文中插入數(shù)據(jù)。在這種情況下,我該如何避免循環(huán)其他循環(huán)。我該如何修復(fù)它?views.py我正在使用beautifulsoup從wiki中獲取數(shù)據(jù)。正在上傳圖像。它返回以下內(nèi)容:模板.html{%extends 'profilecontent/base.html' %}{%block content%}    <div class="container-home">        <div class="home-wrapper home-wrapper-first">            <p class='home-matches'>Przysz?e mecze <span class='home-week'>W3 D2</span></p>                <div class="match-wrapper">                    <table>                        {%for second_team in second_team_names%}                            {%for first_team in first_team_names %}                        {%for hour_game in hours_games%}                            <tr><td>{{first_team}}</td><td>{{hour_game}}</td><td>{{second_team}}</td></tr>                            {%endfor%}                        {%endfor%}                        {%endfor%}                    </table>                             </div>        </div>        <div class="home-wrapper home-wrapper-second">        </div>    </div>{%endblock%}views.pyfrom bs4 import BeautifulSoupimport requestsdef home(request):    source = requests.get('https://lol.gamepedia.com/Ultraliga/Season_3').text    soup = BeautifulSoup(source, 'lxml')    first_team_names = []    second_team_names = []    td1s = None    td2s = None    hours_games = ['17:30', '18:30', '19:30', '20:30']    tables = soup.find_all('table', class_='wikitable matchlist')    for table in tables:        td1s = table.find_all('td', class_='matchlist-team1')        td2s = table.find_all('td', class_='matchlist-team2')    for td in td1s:        span = td.find('span')        first_team_names.append(span.text)    for td in td2s:        span = td.find('span')        second_team_names.append(span.text)    context = {        'first_team_names':first_team_names,        'second_team_names':second_team_names,        'hours_games':hours_games,        }    return render(request, 'profilecontent/home.html', context)
查看完整描述

1 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

您必須將三個(gè)列表放在視圖中,然后將其發(fā)送到模板。然后同時(shí)在那里迭代它,如下所示...zip


def home(request):


    ...Your Logic...


    context = { "all_teams": zip(first_team_names, second_team_names, hours_games)}


    return render(request, 'profilecontent/home.html', context)

現(xiàn)在,解壓縮模板并同時(shí)對(duì)其進(jìn)行迭代...


{%extends 'profilecontent/base.html' %}

{%block content%}

    <div class="container-home">

        <div class="home-wrapper home-wrapper-first">

            <p class='home-matches'>Przysz?e mecze <span class='home-week'>W3 D2</span></p>

                <div class="match-wrapper">

                    <table>

                        {% for data in all_teams %}


                            <tr><td>{{ data.0.first_team }}</td><td>{{ data.2.hour_game }}</td><td>{{ data.1.second_team }}</td></tr>    


                        {%endfor%}

                    </table>             

                </div>

        </div>

        <div class="home-wrapper home-wrapper-second">


        </div>

    </div>

{%endblock%}


查看完整回答
反對(duì) 回復(fù) 2022-08-25
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)