Commit a0cca0a3 authored by AntonKras's avatar AntonKras
Browse files

Сделан редирект при вводе короткой ссылки

parent 38a8d92f
from flask import Flask
from flask import render_template, redirect, request
from flask import Flask, render_template, redirect, make_response
app = Flask(__name__)
@app.route('/', methods=['GET'])
def main():
yml_dict = extract_data_from_yml('static/urls.yml')
return render_template('index.html')
@app.route('/redir', methods=['GET'])
def redir():
@app.route('/', defaults={'path': ''})
def redirect_somewhere(path):
yml_dict = extract_data_from_yml('static/urls.yml')
return redirect("http://" + yml_dict['ah712'] + "/")
if path in yml_dict:
return redirect("https://www." + yml_dict[path])
return make_response(404)
def extract_data_from_yml(urls) -> dict:
......@@ -27,12 +29,14 @@ def extract_data_from_yml(urls) -> dict:
with open(urls, 'r') as f:
content ='\n')
content = content[:-1]
for elem in content:
final_dict[elem.split(':')[0]] = elem.split(':')[1]
return final_dict
if __name__ == '__main__':
\ No newline at end of file
......@@ -5,6 +5,11 @@
Введите ссылку в адресной строке
{#<p><b>Введите длинную ссылку:</b><br>#}
{#<form action="/add">#}
{# <input type="text" size="40">#}
{# <button>ff</button>#}
\ No newline at end of file
Supports Markdown
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