cookie page

This commit is contained in:
zeroth 2019-04-17 16:59:25 +01:00
parent d58346e7f4
commit 798d1adcf4
4 changed files with 18 additions and 13 deletions

View File

@ -1,5 +1,4 @@
from flask import Flask, url_for, render_template, Markup, redirect, request, flash from flask import Flask, url_for, render_template, Markup, redirect, request, flash, session, make_response
from flask import session as login_session
from config import Config from config import Config
import json import json
import os import os
@ -12,6 +11,8 @@ app = Flask(__name__, static_url_path='', static_folder="static", template_folde
app.jinja_env.add_extension('jinja2.ext.loopcontrols') app.jinja_env.add_extension('jinja2.ext.loopcontrols')
app.config.from_object(Config) app.config.from_object(Config)
#############cookie stuff
# app.secret_key = os.urandom(24)
# setting variables for holding paths, folder names and the one file for description # setting variables for holding paths, folder names and the one file for description
path = "static/files/" path = "static/files/"
@ -25,7 +26,6 @@ positioninarray = 8 #counter
listofdicts=[] #to be able to import and use json content listofdicts=[] #to be able to import and use json content
datafromjson = [] datafromjson = []
#test getting json file from id #test getting json file from id
id = "17" id = "17"
jsonfilefordescription = "files/"+id+"/"+id+".json" jsonfilefordescription = "files/"+id+"/"+id+".json"
@ -34,11 +34,6 @@ jsonfilefordescription = "files/"+id+"/"+id+".json"
pathofwords = [] pathofwords = []
pathofnumbers = [] pathofnumbers = []
#reading wordlist.json
with open('wordlist.json', 'r') as f:
wordlist_dict = json.load(f)
#listing paths and files, not in order but well... #listing paths and files, not in order but well...
for path, subdirs, files in os.walk(path): for path, subdirs, files in os.walk(path):
for name in files: for name in files:
@ -71,14 +66,17 @@ print("-------------------------")
dict = {} #dict for the form entries dict = {} #dict for the form entries
with open("static/"+jsonfilefordescription, 'r') as f: with open("static/"+jsonfiles[4], 'r') as f:
data_dict = json.load(f) data_dict = json.load(f)
datafromjson = data_dict["files"] datafromjson = data_dict["files"]
print(datafromjson) print(datafromjson)
@app.route("/") @app.route("/")
def home(): def home():
return render_template('home.html') words = ["way", "blablabla", "uqhdiuqsiud"]
res = make_response(render_template('home.html'))
res.set_cookie("qhdqhd",str(words) , max_age=60*60*24*365*2)
return res
@app.route('/about/') @app.route('/about/')
def about(): def about():
@ -92,7 +90,6 @@ def all():
counter2=0 counter2=0
return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2) return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2)
@app.route('/description') @app.route('/description')
def description(): def description():
#open json file, list filepaths in array and loop with thefile #open json file, list filepaths in array and loop with thefile
@ -116,7 +113,11 @@ def description():
@app.route('/diverge', methods=['GET']) @app.route('/diverge', methods=['GET'])
def diverge(): def diverge():
searchterm=request.args.get('search') searchterm=request.args.get('search')
return render_template('diverge.html', wordlist_dict=wordlist_dict, searchterm=searchterm) return render_template('diverge.html', searchterm=searchterm)
@app.route('/listofwords')
def listofwords():
return render_template('listofwords.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)

View File

@ -15,6 +15,7 @@
<li><a href="{{ url_for('about') }}">About</a></li> <li><a href="{{ url_for('about') }}">About</a></li>
<li><a href="{{ url_for('description') }}">Description</a></li> <li><a href="{{ url_for('description') }}">Description</a></li>
<li><a href="{{ url_for('all') }}">All files</a></li> <li><a href="{{ url_for('all') }}">All files</a></li>
<li><a href="{{ url_for('listofwords') }}">List of words</a></li>
</ul> </ul>
</nav></strong> </nav></strong>
</div> </div>
@ -24,4 +25,4 @@
{% endblock %} {% endblock %}
</div> </div>
</body> </body>
</html> </html>

View File

@ -0,0 +1,3 @@
{% extends "layout.html" %}
{% block content %}
{% endblock %}