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

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

為什么我無(wú)法將“上下文”轉(zhuǎn)移到從端點(diǎn) Django 應(yīng)用程序到 HTML 頁(yè)面?

為什么我無(wú)法將“上下文”轉(zhuǎn)移到從端點(diǎn) Django 應(yīng)用程序到 HTML 頁(yè)面?

一只名叫tom的貓 2023-12-19 20:40:02
我在將 {context} 從 Django 端點(diǎn)傳輸?shù)?HTML 時(shí)遇到問(wèn)題。我向項(xiàng)目添加了第二個(gè)應(yīng)用程序(第一個(gè)是“任務(wù)”,一切正常,第二個(gè)是“注釋”,問(wèn)題出在這個(gè))。我不知道為什么,但是來(lái)自 context 的信息沒(méi)有傳輸?shù)?HTML。Python:notes/views.py@login_required(login_url='/user_login/')def notes_list(request, *args, **kwargs):if request.method == "POST":    name = request.POST.get("name")    description = request.POST.get("description")    new_note = Notes.objects.create(        name=name,        description=description,        user=request.user        )    new_note.save()    return redirect("/notes_list/")notes = Notes.objects.all().filter(user=request.user)print("notes", notes)context = {    notes: "notes",}return render(request, 'notes_list.html', context)HTML:模板/notes_list.htmlList:{%for note in notes%}<b>Title:</b>    <textarea  class="form-control" rows="1" cols="1"  name='name' >{{note.name}}</textarea><b>Note:</b>    <textarea  class="form-control" rows="3" cols="1"  name='description' >{{note.description}}</textarea>{%endfor%}當(dāng)我訪問(wèn) http://127.0.0.1:8000/notes_list/ 時(shí),我只看到“List:”和空白頁(yè)(沒(méi)有注釋列表)。模型數(shù)據(jù)庫(kù)是正確的 - print("notes",notes) 在控制臺(tái)中打印所有行,因此一切正常。這是settings.py 文件:    TEMPLATES = [    {        'BACKEND': 'django.template.backends.django.DjangoTemplates',        'DIRS': [os.path.join(BASE_DIR, 'templates')],        'APP_DIRS': True,        'OPTIONS': {            'context_processors': [                'django.template.context_processors.debug',                'django.template.context_processors.request',                'django.contrib.auth.context_processors.auth',                'django.contrib.messages.context_processors.messages',            ],        },     },   ]
查看完整描述

1 回答

?
慕勒3428872

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

改變

context = {
    notes: "notes",
}

context = {
    "notes": notes,
}

同時(shí)在 中的 {% 之后和 %} 之前添加空格template


查看完整回答
反對(duì) 回復(fù) 2023-12-19
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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