Initial commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
wiki-pages/*
|
||||
webroot/*
|
||||
venv/
|
||||
__pycache__/
|
||||
*.swp
|
BIN
docs/amicheletti_python-flask.pdf
Normal file
BIN
docs/amicheletti_python-flask.pdf
Normal file
Binary file not shown.
68
main.py
Normal file
68
main.py
Normal file
@@ -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'<a href="/wiki/{page[:-3]}">{page[:-3]}</a><br/>'
|
||||
return render_template('index.html', pages=pages_string)
|
||||
|
||||
@app.route('/wiki/<page>')
|
||||
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/<page>')
|
||||
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
|
||||
)
|
25
templates/forms/edit-page.html
Normal file
25
templates/forms/edit-page.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<header>
|
||||
{% include 'partials/site-wide-header.html' %}
|
||||
</header>
|
||||
<h1>{{page_title}}</h1>
|
||||
<form action='/submit-edit' method='POST'>
|
||||
<input type='hidden' name='page' value='{{page_title}}'>
|
||||
|
||||
<label>Username:</label><br/>
|
||||
<input type='text' name='username'><br/>
|
||||
<label>Password:</label><br/>
|
||||
<input type='password' name='password'><br/>
|
||||
|
||||
<label>Content:</label><br/>
|
||||
<textarea name='content'>{{content}}</textarea><br/>
|
||||
|
||||
<input type='submit'>
|
||||
</form>
|
||||
<footer>
|
||||
{% include 'partials/site-wide-footer.html' %}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
13
templates/index.html
Normal file
13
templates/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<body>
|
||||
<header>
|
||||
{% include 'partials/site-wide-header.html' %}
|
||||
</header>
|
||||
Welcome to My Wiki Site!<br/>
|
||||
Pages:<br/>
|
||||
{{pages|safe}}
|
||||
<footer>
|
||||
{% include 'partials/site-wide-footer.html' %}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
2
templates/partials/site-wide-footer.html
Normal file
2
templates/partials/site-wide-footer.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<hr/>
|
||||
Powered by deadwiki
|
2
templates/partials/site-wide-header.html
Normal file
2
templates/partials/site-wide-header.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<a href='/'>Home Page</a>
|
||||
<hr/>
|
13
templates/wiki-page.html
Normal file
13
templates/wiki-page.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<body>
|
||||
<header>
|
||||
{% include 'partials/site-wide-header.html' %}
|
||||
</header>
|
||||
<h1>{{page_title}}</h1>
|
||||
{{content|safe}}<br/>
|
||||
<a href='/edit/{{page_title}}'>Edit Page</a>
|
||||
<footer>
|
||||
{% include 'partials/site-wide-footer.html' %}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user