6

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

from django.urls import path
from . import views


urlpatterns = [
    path('', views.home, name='home'),
    path('search_titles', views.searchTitles, name='search_titles'),
    path('stats/', views.dataStats, name='stats'),

    path('robustSearch/', views.robustSearch, name='robustSearch'),
]

And my views.py file

def robustSearch(request):
    
    if request.method == 'POST':
        file = request.FILES['titles_file']
        df = pd.read_csv(file)
        df.dropna(inplace=True)
        counting = df.counts()
    context={
        'counting': counting,
    }
    return render(request, 'result_titles.html', context)

and my POST Form file is

<form action="robustSearch" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-inline">
     <input type="file" name="titles_file" class="form-control input-sm mr-2">
     <button type="submit" class="btn btn-primary">Search</button>
</div>  
</form>

anyone can please point out where I'm doing wrong or how can I get this purpose fulfilled

2 Answers 2

4

The URL should be:

<form action="/robustSearch/" method="POST" enctype="multipart/form-data">
  …
</form>

but it is better to work with the {% url … %} template tag [Django-doc]:

<form action="{% url 'robustSearch' %}" method="POST" enctype="multipart/form-data">
  …
</form>
Sign up to request clarification or add additional context in comments.

Comments

2

you lack "/" in your link; this causes that error

in ur urls

path('robustSearch/', views.robustSearch, name='robustSearch'),

and in ur html

action='robustSearch'

it should be

action='robustSearch/'

or you can consult django - url with automatic slash adding

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.