commit af38770285d00981294da54c76dbf0114055b709 Author: deadvey Date: Tue Oct 7 12:58:31 2025 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82bd622 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +wiki-pages/* +webroot/* +venv/ +__pycache__/ +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..2680e52 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A basic wiki backend written in Python Flask diff --git a/config.py b/config.py new file mode 100644 index 0000000..89a09e0 --- /dev/null +++ b/config.py @@ -0,0 +1,3 @@ +host='0.0.0.0' +port=8080 +debug=True diff --git a/docs/amicheletti_python-flask.pdf b/docs/amicheletti_python-flask.pdf new file mode 100644 index 0000000..f60093f Binary files /dev/null and b/docs/amicheletti_python-flask.pdf differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..9f84222 --- /dev/null +++ b/main.py @@ -0,0 +1,68 @@ +from flask import Flask, render_template, request, redirect +from markdown_it import MarkdownIt +import os +import config + +md = MarkdownIt().enable('table') + +app = Flask(__name__) + +@app.route('/') +def index(): + pages = os.listdir('./wiki-pages') + pages_string = '' + for page in pages: + if page[-3:] == '.md': + pages_string += f'{page[:-3]}
' + return render_template('index.html', pages=pages_string) + +@app.route('/wiki/') +def wiki_page(page): + if os.path.isfile(f'./wiki-pages/{page}.md'): + file_contents = md.render(open(f'./wiki-pages/{page}.md', 'r').read()) + return render_template( + 'wiki-page.html', + content=file_contents, + page_title=page + ) + else: + return 'Page does not exist' + +@app.route('/edit/') +def edit_page(page): + if os.path.isfile(f'./wiki-pages/{page}.md'): + file_contents = open(f'./wiki-pages/{page}.md', 'r').read() + return render_template( + 'forms/edit-page.html', + content=file_contents, + page_title=page + ) + else: + return render_template( + 'forms/edit-page.html', + content='New Page!', + page_title=page + ) + +# Forms +@app.route('/submit-edit', methods=['POST']) +def handle_data(): + page = request.form['page'] + content = request.form['content'] + username = request.form['username'] + password = request.form['password'] + + with open(f'./wiki-pages/{page}.md', 'w') as file: + print(content) + file.write(content) + file.close() + + return redirect(f'/wiki/{page}', 302) + + +if __name__ == '__main__': + app.run( + debug = config.debug, + host = config.host, + port = config.port + ) diff --git a/templates/forms/edit-page.html b/templates/forms/edit-page.html new file mode 100644 index 0000000..2575065 --- /dev/null +++ b/templates/forms/edit-page.html @@ -0,0 +1,25 @@ + + + +
+ {% include 'partials/site-wide-header.html' %} +
+

{{page_title}}

+
+ + +
+
+
+
+ +
+
+ + +
+
+ {% include 'partials/site-wide-footer.html' %} +
+ + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..aee0c67 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + +
+ {% include 'partials/site-wide-header.html' %} +
+ Welcome to My Wiki Site!
+ Pages:
+ {{pages|safe}} +
+ {% include 'partials/site-wide-footer.html' %} +
+ + diff --git a/templates/partials/site-wide-footer.html b/templates/partials/site-wide-footer.html new file mode 100644 index 0000000..758e546 --- /dev/null +++ b/templates/partials/site-wide-footer.html @@ -0,0 +1,2 @@ +
+Powered by deadwiki diff --git a/templates/partials/site-wide-header.html b/templates/partials/site-wide-header.html new file mode 100644 index 0000000..846ad6e --- /dev/null +++ b/templates/partials/site-wide-header.html @@ -0,0 +1,2 @@ +Home Page +
diff --git a/templates/wiki-page.html b/templates/wiki-page.html new file mode 100644 index 0000000..e5dc399 --- /dev/null +++ b/templates/wiki-page.html @@ -0,0 +1,13 @@ + + +
+ {% include 'partials/site-wide-header.html' %} +
+

{{page_title}}

+ {{content|safe}}
+ Edit Page + + +