내 템플릿에 두 가지 형태가 있습니다 하나의 서버에서 파일 삭제를 활성화하기 위해, 뭔가 두 번째 게시 :플라스크 : 양식 제출 후 같은 페이지로 리디렉션
<div style="margin-bottom:150px;">
<h4>Delete</h4>
<form method="post" action="/delete">
<div class="form-group">
<input type="hidden" name="delete_input"></input>
</div>
<button type="submit" class="btn btn-danger" id="btnSignUp">Delete</button>
</form>
</div>
<div style="margin-bottom:150px;">
<h4>URLs</h4>
<form method="post" action="/">
<div class="form-group">
<textarea class="form-control" rows="5" id="urls" name="url_area"></textarea>
</div>
<button type="submit" class="btn btn-primary" id="btnSignUp">Urls</button>
</form>
</div>
가 app.py
은 다음과 같습니다 내를 :
@app.route("/")
def main():
return render_template('index.html')
@app.route('/', methods=['POST'])
def parse_urls():
_urls = request.form['url_area'].split("\n")
image_list = get_images(_urls)
return render_template('index.html', images=image_list)
@app.route('/delete', methods=['POST'])
def delete_images():
file_list = [f for f in os.listdir("./static") if f.endswith(".png")]
for f in file_list:
os.remove("./static/" + f)
image_list = []
conn = sqlite3.connect('_db/database.db')
curs = conn.cursor()
sql = "DROP TABLE IF EXISTS images"
curs.execute(sql)
conn.commit()
conn.close()
return render_template('index.html', images=image_list)
두 가지 문제 : 나는 subm 후 페이지를 다시로드 할 때 내가 양식 재 제출 메시지가
- itting
- 내가 모든 것을
내가 볼때 하나 개의 URL을하고 싶은 형태를, 그래서 사용은 중복 제출을 피하기 위해 리디렉션 및 삭제 호출 한 후, 나는 인덱스로 리디렉션해야 할 필요가있다.
어떻게하면 제대로 할 수 있습니까?
나는 대략 redirect
과 url_for
을 알고 있지만 어떻게 같은 페이지로 리디렉션합니까?