Updated Question:
Wrong redirection of URL in Django. I have this:
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'),
]
for testing purposes, I m using a print statement. So there is no problem until printing print(context)
but the problem is it goes to 'StockPrediction/greet.html'
not 'StockPrediction/chart.html'
. which I need.
2
Answers
You should use ajax request:
in your view:
also you should care about crsf-token. Documentation
your can
POST
itGET
it or put it as a variable in yoururl
. here is a post approach:using
jquery
:In your view you can get the data as json and return josn as response