Browse Source

the json works all in same file

master
jules 6 years ago
parent
commit
cab2bda5e9
  1. 19
      contextualise.py
  2. 3
      templates/about.html
  3. 20
      templates/description-prev.html
  4. 2
      templates/description.html
  5. 1
      templates/layout.html

19
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)

3
templates/about.html

@ -1,6 +1,3 @@
<!DOCTYPE html>
<html>
<body>
{% extends "layout.html" %}
{% block content %}
<div class="about">

20
templates/description-prev.html

@ -1,20 +0,0 @@
{% 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 %}

2
templates/description.html

@ -6,7 +6,7 @@
<div>{{ message }}</div>
{% endfor %}
<form method="POST" action="/write">
<form method="POST" action="/get-data">
<fieldset>
{{ form.hidden_tag() }}
<div>{{ form.name.label }} {{ form.name }}</div>

1
templates/layout.html

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PARTOUT TITRE PARTOUT</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>

Loading…
Cancel
Save