【发布时间】:2019-11-13 22:25:20
【问题描述】:
我想在主页上提交表单后重定向并返回视图。不幸的是,POST 之后什么都没有发生。
我的主页:
def home(request):
if request.method == 'POST':
url = request.POST['url']
bokeh(request,url)
return render(request,'home.html')
def bokeh(request,url):
//my calculation logic
return render(request,'bokeh.html')
当然,我会发送其他属性,例如字典等,但是当我在浏览器中硬编码我的 url 时,它可以正常工作。在我的主页中单击我的表单上的提交后,没有任何反应。
编辑
我的散景功能是这样的:
def bokeh(request,url):
source = urllib.request.urlopen(url).read()
soup = bs.BeautifulSoup(source, 'lxml')
descrp = [description.text for description in soup.find_all('p', class_="commit-title")]
author = [author.text for author in soup.find_all('a', class_="commit-author")]
dict1 = dict(zip(descrp,author))
dict2 = dict(Counter(dict1.values()))
label = list(dict2.keys())
value = list(dict2.values())
plot = figure(title='Github Effort',x_range=label,y_range=(0,30), plot_width=400, plot_height=400)
plot.line(label,value,line_width = 2)
script,div = components(plot)
return render(request,'bokeh.html',{'script': script,'div': div})
还有我的 urls.py
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^bokeh/(?P<url>\w+)/$',views.bokeh,name='bokeh',url='url'),
]
此时我得到了 TypeError: url() got an unexpected keyword argument 'url'
【问题讨论】: