Browse Source

the form now saves output to a json file. readded the old version of the description template under the name description-prev.html to remove call to layout.html

master
Cristina Cochior 6 years ago
parent
commit
1744735471
  1. 24
      startform.py
  2. 20
      templates/description-prev.html

24
startform.py

@ -3,6 +3,7 @@ from flask import Flask, url_for, render_template, Markup, redirect, request, fl
from flask import session as login_session
from forms import ReusableForm
from config import Config
import json_actions
import json
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
@ -14,15 +15,20 @@ def description():
form = ReusableForm(request.form)
print (form.errors)
if request.method == 'POST' and form.validate():
return 'Success'
return render_template('description.html', form=form)
return 'Success!'
return render_template('description-prev.html', form=form)
if __name__ == '__main__':
app.run(debug = True)
dict={}
@app.route('/get-data', methods=['GET', 'POST'])
def savepost():
if request.method=='POST':
dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']}
# open with "a" if the file should concatenate content
with open("data_file.json", "w") as write_file:
json.dump(dict, write_file)
return "The JSON file is ready."
else:
return "Error"

20
templates/description-prev.html

@ -0,0 +1,20 @@
{% block content %}
<div class="description">
<h2 style = "text-align: center;">Write something very interesting here.</h2>
{% for message in form.name.errors %}
<div>{{ message }}</div>
{% endfor %}
<form method="POST" action="/get-data">
<fieldset>
{{ form.hidden_tag() }}
<div>{{ form.name.label }} {{ form.name }}</div>
<div>{{ form.email.label }} {{ form.email }}</div>
<div>{{ form.friend.label }} {{ form.friend }}</div>
<div>{{ form.content.label }} {{ form.content }}</div>
<div>{{ form.submit }}</div>
</fieldset>
</form>
</div>
{% endblock %}
Loading…
Cancel
Save