diff --git a/editable_text.txt b/editable_text.txt new file mode 100644 index 0000000..cd7988d --- /dev/null +++ b/editable_text.txt @@ -0,0 +1 @@ +How are you my love \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b3453a2..fb325fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -appdirs==1.4.3 -click==6.7 -Flask==0.12 -itsdangerous==0.24 -Jinja2==2.9.5 -MarkupSafe==1.0 -packaging==16.8 -pyparsing==2.2.0 -six==1.10.0 -Werkzeug==0.11.15 +appdirs +click +Flask +itsdangerous +Jinja2 +MarkupSafe +packaging +pyparsing +six +Werkzeug \ No newline at end of file diff --git a/routes.py b/routes.py index b4377d8..05282ab 100644 --- a/routes.py +++ b/routes.py @@ -1,19 +1,34 @@ -from flask import Flask, render_template +from flask import Flask, render_template, request, redirect, url_for + app = Flask(__name__) -# two decorators, same function +# Path to the text file +TEXT_FILE = 'editable_text.txt' + +# Load text from file +def load_text(): + try: + with open(TEXT_FILE, 'r') as file: + return file.read() + except FileNotFoundError: + return '' + +# Save text to file +def save_text(text): + with open(TEXT_FILE, 'w') as file: + file.write(text) + @app.route('/') -@app.route('/index.html') +@app.route('/index.html') # get method def index(): - return render_template('index.html', the_title='Tiger Home Page') - -@app.route('/symbol.html') -def symbol(): - return render_template('symbol.html', the_title='Tiger As Symbol') + text = load_text() + return render_template('index.html', the_title='Text Editor', text=text) -@app.route('/myth.html') -def myth(): - return render_template('myth.html', the_title='Tiger in Myth and Legend') +@app.route('/save', methods=['POST']) +def save(): + text = request.form['editor'] + save_text(text) + return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True) diff --git a/templates/index.html b/templates/index.html index b382058..08f8cb5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,27 +1,15 @@ -{% extends 'base.html' %} - -{% block body %} - - -
-Photo by John and Karen Hollingsworth, retouched by Zwoenitzer (Fish & Wildlife Service, ID WO0409-33F) [Public domain] via Wikimedia Commons
- -This is the index page for my example Flask app.
- -The tiger (Panthera tigris) is the largest cat species, most recognisable for their pattern of dark vertical stripes on reddish-orange fur with a lighter underside. The species is classified in the genus Panthera with the lion, leopard, jaguar and snow leopard. Tigers are apex predators, primarily preying on ungulates such as deer and bovids. They are territorial and generally solitary but social animals, often requiring large contiguous areas of habitat that support their prey requirements. This, coupled with the fact that they are indigenous to some of the more densely populated places on Earth, has caused significant conflicts with humans.
- -Tigers once ranged widely across eastern Eurasia, from the Black Sea in the west, to the Indian Ocean in the south, and from Kolyma to Sumatra in the east. Over the past 100 years, they have lost 93% of their historic range, and have been extirpated from Western and Central Asia, from the islands of Java and Bali, and from large areas of Southeast, Southern and Eastern Asia. Today, they range from the Siberian taiga to open grasslands and tropical mangrove swamps. The remaining six tiger subspecies have been classified as endangered by the International Union for Conservation of Nature (IUCN). The global population in the wild is estimated to number between 3,062 and 3,948 individuals, down from around 100,000 at the start of the 20th century, with most remaining populations occurring in small pockets isolated from each other, of which about 2,000 exist on the Indian subcontinent. A 2016 global census estimated the population of wild tigers at approximately 3,890 individuals.
- -(Text from Wikipedia)
- - -{% endblock %} + + + + + +