我有一個django應用程序,我上傳2個文件並且想在它們上運行一個python腳本(proto2.py)。在上傳的文件上執行python代碼
在我的HTML代碼,我增加了一個按鈕來執行一個文件,但它沒有工作:失敗給
<div>Relay 1:
<form action="{% url "nettoyage"%}" method="POST">
{% csrf_token %}
<input type="submit" value="Toggle" id="toggle1" />
</form>
</div>
原因: CSRF令牌丟失或不正確。
urls.py:
url(r'^nettoyage/$', 'nettoyage',name='nettoyage'),
views.py:
def nettoyage(request):
if request.method == 'POST':
import proto2
return #Something, normally a HTTPResponse, using django
proto2.py:
file = xlrd.open_workbook('~/Paye_P5_test.xlsx',encoding_override='utf-8')
sheet = file.sheet_by_name('Feuil1')
headers = [str(cell.value) for cell in sheet.row(0)]
values = []
for rowind in range(sheet.nrows)[1:]:
values.append([ cell.value for cell in sheet.row(rowind)])
data2=pandas.DataFrame(data=values,columns=headers)
resume=data2['Résumé']
resume = resume.str.lower()
resume = resume.str.replace("'", " ")
remov_punct = str.maketrans({key: None for key in string.punctuation})
resume = resume.str.translate(remov_punct)
resume = html.unescape(resume)
stop_words = get_stop_words('french')
resume = resume.str.split()
resume = resume.apply(lambda x: [item for item in x if item not in stop_words])
# Porter Stemmer Algo
stemmer = SnowballStemmer("french")
resume = resume.apply(lambda x: [stemmer.stem(item) for item in x])
resume[0]
請顯示您的'urls.py'文件。 –
「{%url」nettoyage「%}'生成的網址是什麼? –
這一個:url(r'^ nettoyage/$','nettoyage',name ='nettoyage'), – celianou