def short(): full_url = request.form.get('full_url').strip().lower() if not full_url.startswith('http'): full_url = f'http://{full_url}' try: requests.get(full_url) except Exception as err: return {'short': 'Указанный Вами ресурс недоступен'} url = Urls.get(full_url=full_url) if url is None: short_url = shortener(full_url) short_json = {'short': short_url} else: short_json = {'short': f'{SERVER_URL}/{url.hashed_url}'} return short_json
def redirect_url(hashed_url): full_url = Urls.get(hashed_url=hashed_url) return redirect(full_url.full_url)