Flask together with `POST` method doesn’t yield any output from slovnik.seznam.cz

I have a flask structure as below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>root@k2:/mnt/c/Users/k2/myenvGPU32/myflaskapp# ls -lR . .: total 8
-rwxrwxrwx 1 root root 128 Jun 10 10:59 T.py
-rwxrwxrwx 1 root root 128 Jun 10 10:55 T.py~
-rwxrwxrwx 1 root root 926 Jun 10 20:17 app.py
-rwxrwxrwx 1 root root 2969 Jun 10 19:57 app.py~ drwxrwxrwx 1 root root 4096 Jun 10 20:17 templates
./templates: total 12
-rwxrwxrwx 1 root root 1283 Jun 10 20:17 index.html
-rwxrwxrwx 1 root root 6104 Jun 10 19:58 index.html~
</code>
<code>root@k2:/mnt/c/Users/k2/myenvGPU32/myflaskapp# ls -lR . .: total 8 -rwxrwxrwx 1 root root 128 Jun 10 10:59 T.py -rwxrwxrwx 1 root root 128 Jun 10 10:55 T.py~ -rwxrwxrwx 1 root root 926 Jun 10 20:17 app.py -rwxrwxrwx 1 root root 2969 Jun 10 19:57 app.py~ drwxrwxrwx 1 root root 4096 Jun 10 20:17 templates ./templates: total 12 -rwxrwxrwx 1 root root 1283 Jun 10 20:17 index.html -rwxrwxrwx 1 root root 6104 Jun 10 19:58 index.html~ </code>
root@k2:/mnt/c/Users/k2/myenvGPU32/myflaskapp# ls -lR . .: total 8
-rwxrwxrwx 1 root root  128 Jun 10 10:59 T.py
-rwxrwxrwx 1 root root  128 Jun 10 10:55 T.py~
-rwxrwxrwx 1 root root  926 Jun 10 20:17 app.py
-rwxrwxrwx 1 root root 2969 Jun 10 19:57 app.py~ drwxrwxrwx 1 root root 4096 Jun 10 20:17 templates

./templates: total 12
-rwxrwxrwx 1 root root 1283 Jun 10 20:17 index.html
-rwxrwxrwx 1 root root 6104 Jun 10 19:58 index.html~

(but the button Translate doesn’t produce any results)
with these files app.py:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from flask import Flask, render_template, request, jsonify
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/translate', methods=['POST'])
def translate():
term = request.json.get('term')
url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
translation_div = soup.find('div', class_='entry')
if translation_div:
translation = translation_div.text.strip()
return jsonify(success=True, translation=translation)
else:
return jsonify(success=False, error='Translation not found')
return jsonify(success=False, error='Translation service unavailable')
if __name__ == '__main__':
app.run(port=5000, debug=True)
</code>
<code>from flask import Flask, render_template, request, jsonify import requests from bs4 import BeautifulSoup app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/translate', methods=['POST']) def translate(): term = request.json.get('term') url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}' response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') translation_div = soup.find('div', class_='entry') if translation_div: translation = translation_div.text.strip() return jsonify(success=True, translation=translation) else: return jsonify(success=False, error='Translation not found') return jsonify(success=False, error='Translation service unavailable') if __name__ == '__main__': app.run(port=5000, debug=True) </code>
from flask import Flask, render_template, request, jsonify
import requests
from bs4 import BeautifulSoup

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/translate', methods=['POST'])
def translate():
    term = request.json.get('term')
    url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
    response = requests.get(url)
    if response.status_code == 200:
        soup = BeautifulSoup(response.text, 'html.parser')
        translation_div = soup.find('div', class_='entry')
        if translation_div:
            translation = translation_div.text.strip()
            return jsonify(success=True, translation=translation)
        else:
            return jsonify(success=False, error='Translation not found')
    return jsonify(success=False, error='Translation service unavailable')

if __name__ == '__main__':
    app.run(port=5000, debug=True)

and

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Translate</title>
<script>
function translate() {
const term = document.getElementById('translateTerm').value;
fetch('/translate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ term })
})
.then(response => response.json())
.then(data => {
const translationDiv = document.getElementById('translation');
if (data.success) {
translationDiv.textContent = data.translation;
translationDiv.style.display = 'block';
} else {
translationDiv.textContent = data.error;
translationDiv.style.display = 'block';
}
});
}
</script>
</head>
<body>
<h1>Translate</h1>
<textarea id="translateTerm" placeholder="Enter term to translate"></textarea>
<button onclick="translate()">Translate</button>
<div id="translation" style="display:none;"></div>
</body>
</html>
</code>
<code><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Translate</title> <script> function translate() { const term = document.getElementById('translateTerm').value; fetch('/translate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ term }) }) .then(response => response.json()) .then(data => { const translationDiv = document.getElementById('translation'); if (data.success) { translationDiv.textContent = data.translation; translationDiv.style.display = 'block'; } else { translationDiv.textContent = data.error; translationDiv.style.display = 'block'; } }); } </script> </head> <body> <h1>Translate</h1> <textarea id="translateTerm" placeholder="Enter term to translate"></textarea> <button onclick="translate()">Translate</button> <div id="translation" style="display:none;"></div> </body> </html> </code>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Translate</title>
    <script>
        function translate() {
            const term = document.getElementById('translateTerm').value;
            fetch('/translate', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ term })
            })
            .then(response => response.json())
            .then(data => {
                const translationDiv = document.getElementById('translation');
                if (data.success) {
                    translationDiv.textContent = data.translation;
                    translationDiv.style.display = 'block';
                } else {
                    translationDiv.textContent = data.error;
                    translationDiv.style.display = 'block';
                }
            });
        }
    </script>
</head>
<body>
    <h1>Translate</h1>
    <textarea id="translateTerm" placeholder="Enter term to translate"></textarea>
    <button onclick="translate()">Translate</button>
    <div id="translation" style="display:none;"></div>
</body>
</html>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật