【发布时间】:2020-06-17 11:11:36
【问题描述】:
更新问题:
Django 中的 URL 重定向错误。我有这个:
views.py.
def graph(request):
if request.method == 'POST' and 'text' in request.POST:
print("testing....")
print(request.POST.get('text'))
name = request.POST.get('text')
context = {
'name': name,
}
print(context)
return render(request, 'StockPrediction/chart.html', context)
else:
return render(request, 'StockPrediction/greet.html')
urls.py
urlpatterns = [
path("", views.greet, name='greet'),
path("index/", views.index, name='Stock Prediction'),
path("prediction/", views.prediction, name='Prediction'),
path("view/", views.graph, name='Graph'),
]
出于测试目的,我正在使用打印语句。所以在打印print(context) 之前没有问题,但问题是它转到'StockPrediction/greet.html' 而不是'StockPrediction/chart.html'。我需要的。
【问题讨论】:
-
删除
company's symbol中的's以改进格式。 -
为什么
request.POST的键中应该有_graph? -
那应该是什么??
-
什么都没有。
if request.method == 'POST'就够了。或and request.is_ajax() -
'_graph' in request.POST:to 因为我有两个提交按钮。
标签: python jquery django ajax django-views