Created
April 25, 2021 08:21
-
-
Save mmdbalkhi/9b4e4ee9d0375413f57c4893cc627ff7 to your computer and use it in GitHub Desktop.
index_site_virgool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/', methods=('GET', 'POST')) | |
def index(): | |
conn = sqlite3.connect('database.db') | |
conn.row_factory = sqlite3.Row | |
if request.method == 'POST': | |
url = request.form['url'] | |
if not url: | |
flash('The URL is required!') | |
return redirect(url_for('index')) | |
url_data = conn.execute('INSERT INTO urls (original_url) VALUES (?)', | |
(url,)) # Write URL data On DB | |
conn.commit() | |
conn.close() | |
url_id = url_data.lastrowid | |
hashid = hashids.encode(url_id) | |
short_url = request.host_url + hashid | |
return render_template('index.html', short_url=short_url) | |
return render_template('index.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment