如何解决 Django POST URL 错误 APPEND_SLASH
how to solve Django POST URL error of APPEND_SLASH
我正在尝试将我的表单 POST 数据放到下一页,但出现错误
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.
我的urls.py文件
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'),
]
还有我的 views.py 文件
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)
我的 POST 表单文件是
<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>
任何人都可以指出我哪里做错了或者我怎样才能实现这个目的
URL应该是:
<form <b>action="/robustSearch/"</b> method="POST" enctype="multipart/form-data">
…
</form>
但最好使用 {% url … %}
template tag [Django-doc]:
<form <b>action="{% url 'robustSearch' %}"</b> method="POST" enctype="multipart/form-data">
…
</form>
您的 link 中缺少“/”;这会导致错误
在你的网址中
path('robustSearch/', views.robustSearch, name='robustSearch'),
在你的 html
action='robustSearch'
我正在尝试将我的表单 POST 数据放到下一页,但出现错误
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.
我的urls.py文件
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'),
]
还有我的 views.py 文件
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)
我的 POST 表单文件是
<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>
任何人都可以指出我哪里做错了或者我怎样才能实现这个目的
URL应该是:
<form <b>action="/robustSearch/"</b> method="POST" enctype="multipart/form-data">
…
</form>
但最好使用 {% url … %}
template tag [Django-doc]:
<form <b>action="{% url 'robustSearch' %}"</b> method="POST" enctype="multipart/form-data">
…
</form>
您的 link 中缺少“/”;这会导致错误 在你的网址中
path('robustSearch/', views.robustSearch, name='robustSearch'),
在你的 html
action='robustSearch'