Skip to content
Snippets Groups Projects
Commit b44d3b2b authored by William Rukmansa's avatar William Rukmansa
Browse files

First try

parent 81077932
No related merge requests found
Pipeline #12734 failed with stage
Showing
with 47 additions and 0 deletions
File added
File added
File added
File added
hello.py 0 → 100644
from flask import Flask
app = Flask(__name__)
from flask import render_template
@app.route('/hello/')
def hello():
if 'username' in session:
return render_template('hello.html', name=session['username'])
else:
return render_template('hello.html')
from flask import session, redirect, url_for, escape, request
# Set the secret key to some random bytes. Keep this really secret!
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@app.route('/')
def index():
if 'username' in session:
return 'Logged in as %s' % escape(session['username'])
return 'You are not logged in'
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
session['username'] = request.form['username']
return redirect(url_for('index'))
return '''
<form method="post">
<p><input type=text name=username>
<p><input type=submit value=Login>
</form>
'''
@app.route('/logout')
def logout():
# remove the username from the session if it's there
session.pop('username', None)
return redirect(url_for('index'))
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World!</h1>
{% endif %}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment