upload form
This commit is contained in:
parent
c0c3ffca8c
commit
6463f26969
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
default: run
|
default: run
|
||||||
|
|
||||||
run:
|
run:
|
||||||
FLASK_APP=app flask run
|
FLASK_ENV=development FLASK_APP=app flask run
|
||||||
|
22
app.py
22
app.py
@ -1,22 +1,20 @@
|
|||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
|
from flask_wtf.csrf import CSRFProtect
|
||||||
|
from flask_wtf.file import FileField, FileRequired
|
||||||
from wtforms import StringField
|
from wtforms import StringField
|
||||||
from wtforms.validators import DataRequired
|
from wtforms.validators import DataRequired
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.config["SECRET_KEY"] = "foo"
|
||||||
|
app.config["WTF_CSRF_SECRET_KEY"] = "bar"
|
||||||
|
|
||||||
|
|
||||||
|
class UploadForm(FlaskForm):
|
||||||
|
pdf = FileField(validators=[FileRequired()])
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello_world():
|
def home():
|
||||||
form = MyForm(meta={"csrf": False})
|
form = UploadForm()
|
||||||
return render_template("index.html", form=form)
|
return render_template("index.html", form=form)
|
||||||
|
|
||||||
|
|
||||||
class MyForm(FlaskForm):
|
|
||||||
name = StringField("name", validators=[DataRequired()])
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/submit", methods=["GET", "POST"])
|
|
||||||
def submit():
|
|
||||||
print("Success!")
|
|
||||||
return render_template("index.html")
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>THIS IS A TITLE</title>
|
<title>THIS IS A TITLE</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form method="POST" action="/">
|
<form method="POST" action="/submit" enctype="multipart/form-data">
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
{{ form.name.label }} {{ form.name(size=20) }}
|
<input type="file" name="file" />
|
||||||
<input type="submit" value="Go">
|
<input type="submit" value="Go" />
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user