From cab2bda5e9ce0dc4d79c5f5b0183eb558a06374a Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 13 Jan 2019 17:32:38 +0100 Subject: [PATCH] the json works all in same file --- contextualise.py | 19 ++++++++++++++++--- templates/about.html | 3 --- templates/description-prev.html | 20 -------------------- templates/description.html | 2 +- templates/layout.html | 1 + 5 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 templates/description-prev.html diff --git a/contextualise.py b/contextualise.py index f8f2ece..e1ba403 100644 --- a/contextualise.py +++ b/contextualise.py @@ -18,15 +18,28 @@ def home(): def about(): return render_template('about.html') -@app.route('/description/', methods=['GET', 'POST']) +@app.route('/description', methods=['GET', 'POST']) def description(): form = ReusableForm(request.form) print (form.errors) - if request.method == 'POST' and form.validate(): - return 'Success' + if request.method == 'POST' and form.validate(): + return 'Success!' return render_template('description.html', form=form) +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" + if __name__ == '__main__': app.run(debug=True) diff --git a/templates/about.html b/templates/about.html index 4bcc61b..ceb5c38 100644 --- a/templates/about.html +++ b/templates/about.html @@ -1,6 +1,3 @@ - - - {% extends "layout.html" %} {% block content %}
diff --git a/templates/description-prev.html b/templates/description-prev.html deleted file mode 100644 index 5369d22..0000000 --- a/templates/description-prev.html +++ /dev/null @@ -1,20 +0,0 @@ -{% block content %} -
-

Write something very interesting here.

- {% for message in form.name.errors %} -
{{ message }}
- {% endfor %} - -
-
- {{ form.hidden_tag() }} -
{{ form.name.label }} {{ form.name }}
-
{{ form.email.label }} {{ form.email }}
-
{{ form.friend.label }} {{ form.friend }}
-
{{ form.content.label }} {{ form.content }}
-
{{ form.submit }}
-
-
-
- {% endblock %} - diff --git a/templates/description.html b/templates/description.html index 4a5687d..c3f99da 100644 --- a/templates/description.html +++ b/templates/description.html @@ -6,7 +6,7 @@
{{ message }}
{% endfor %} -
+
{{ form.hidden_tag() }}
{{ form.name.label }} {{ form.name }}
diff --git a/templates/layout.html b/templates/layout.html index 918074c..dd68974 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -1,6 +1,7 @@ + PARTOUT TITRE PARTOUT