-1
index.html中有2個html div,綠色和紅色。django如何將數據從一個函數發佈到其他函數?
我想要當我點擊 每個div,/result
頁面出現與消息you have choosed {{ color }} div
。
我應該如何修改這個:
return render(request, 'result.html', {'color': })
我怎樣才能郵寄的功能數據頁面到在NTER頁面的其他功能?
如何通過點擊潛水將每個div的顏色發送到結果頁面?
views.py;
from django.shortcuts import render
from django.http import HttpResponse
def colors(request):
return render(request, 'base.html')
def result(request):
return render(request, 'result.html', {'color': })
base.html文件:
<html>
<head>
<style>
#green {
width:50px;
height:50px;
background:lightgreen;
}
#red {
margin-top:5px;
width:50px;
height:50px;
background:red;
}
</style>
</head>
<body>
result.html:
you have choosed {{ color }} div
urls.py:
from django.conf.urls import include, url
from django.contrib import admin
from secondv.views import hello, colors, result
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^index/', colors),
url(r'^result/', result),
]