我正在尝试使用flask应用程序在pythonanywhere上创建一个论坛或代码共享站点,但由于路径冲突,所以失败了。你知道吗
这是做什么是添加一个新行到一个.csv文件(已经存在)当用户完成和html表单我已经设置。这在/addpythoncode路由上运行良好,但在/addflaskcode路由上失败。你知道吗
我将在下面提供路由和错误日志输出。有人能帮我修一下吗?你知道吗
import sqlite3
from flask import Flask, render_template, request, redirect
import random
import csv
app = Flask(__name__)
@app.route('/addpythoncode', methods=['GET', 'POST'])
def addpycode():
if request.method == 'GET':
return render_template('addpythoncode.html')
else:
dict = {}
dict["codename"] = request.form['codename']
dict["name"] = request.form['name']
dict["code"] = request.form['code']
f = open("/home/Ethankbdca/mysite/Pythonforum.csv", "a")
with f:
fnames = ['codename', 'name', 'code']
writer = csv.DictWriter(f, fieldnames=fnames)
writer.writerow(dict)
return redirect('http://ethankbdca.pythonanywhere.com/pythonforum')
@app.route('/addflaskcode', methods=['GET', 'POST'])
def newflskcode():
if request.method == 'GET':
return render_template('addflaskcode.html')
else:
dict = {}
dict["routename"] = request.form['routecode']
dict["name"] = request.form['name']
dict["routecode"] = request.form['routecode']
f = open("/home/Ethankbdca/mysite/Flaskforum.csv", "a")
with f:
fnames = ['routename', 'name', 'routecode']
writer = csv.DictWriter(f, fieldnames=fnames)
writer.writerow(dict)
return redirect('http://ethankbdca.pythonanywhere.com/flaskforum')
下面是我在错误日志上看到的消息:
2019-03-26 21:21:43,161: OSError: write error
我同意Milad M,但我同意你的观点,没有这样的错误。 更改模板(…)的缩进级别。在写入文件的代码中添加try-except块。你知道吗
这将导致读写问题出现内部服务器错误。你知道吗
相关问题 更多 >
编程相关推荐