I’m trying get my form POST data onto next page but getting the error
You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set. Django can’t redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/robustSearch/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.
my urls.py file
JavaScript
x
12
12
1
from django.urls import path
2
from . import views
3
4
5
urlpatterns = [
6
path('', views.home, name='home'),
7
path('search_titles', views.searchTitles, name='search_titles'),
8
path('stats/', views.dataStats, name='stats'),
9
10
path('robustSearch/', views.robustSearch, name='robustSearch'),
11
]
12
And my views.py file
JavaScript
1
12
12
1
def robustSearch(request):
2
3
if request.method == 'POST':
4
file = request.FILES['titles_file']
5
df = pd.read_csv(file)
6
df.dropna(inplace=True)
7
counting = df.counts()
8
context={
9
'counting': counting,
10
}
11
return render(request, 'result_titles.html', context)
12
and my POST Form file is
JavaScript
1
8
1
<form action="robustSearch" method="POST" enctype="multipart/form-data">
2
{% csrf_token %}
3
<div class="form-inline">
4
<input type="file" name="titles_file" class="form-control input-sm mr-2">
5
<button type="submit" class="btn btn-primary">Search</button>
6
</div>
7
</form>
8
anyone can please point out where I’m doing wrong or how can I get this purpose fulfilled
Advertisement
Answer
The URL should be:
JavaScript
1
3
1
<form action="/robustSearch/" method="POST" enctype="multipart/form-data">
2
…
3
</form>
but it is better to work with the {% url … %}
template tag [Django-doc]:
JavaScript
1
3
1
<form action="{% url 'robustSearch' %}" method="POST" enctype="multipart/form-data">
2
…
3
</form>