Forums

My Flask server app.py not funkcionary on my Android Drive

Hi, I have a problem, my script funkcioniert on web,nur not funkcioniert , not drag my data from server on my App.

This is my app.py

from flask import Flask, jsonify,request
from posts import posts


app=Flask(__name__)

@app.route('/')
def index():
    lang = request.headers.get("Accept-Language", 'sk')[:2]

    p = list(map (lambda post: translate(post, lang), posts))

    return jsonify(p)


def translate(post, lang):
    translation = next (t for t in post['translations'] if t['locale'] == lang)

    return {
        "id": post ['id'],
        "title": translation ['title'],
        "description": translation ['description'],
        "image": post['image'],
}

if __name__ == '__main__':
    app.run()

And, my posts.py

posts = [
  {
        "id": 1,
        "quantity_left": 3,
        "image": "http://samorin.sk/wp-content/uploads/2022/02/feature-content-grants.jpg",
        "translations": [
            {
                "locale": "sk",
                "title":"O dotáciu pre šport, kultúru a sociálnu činnosť sa môžete uchádzať do 20. marca",
                "description":"Mestský úrad Šamorín podľa Všeobecne záväzného nariadenia mesta Šamorín č. 2/2013 o podmienkach poskytovania dotácií právnickým a fyzickým osobám – podnikateľom z rozpočtu mesta (VZN) vyzýva záujemcov o dotáciu na činnosť alebo konkrétnu akciu, aby do 20. marca 2022 (vrátane) podali svoje žiadosti. O dotáciu je možné žiadať v oblasti športu, kultúry a sociálnej.Výzvu na predkladanie žiadostí a tlačivo nájdete tu. Informácie o dotáciách pre oblasť kultúry, športu a sociálnu poskytne na referáte kultúry a športu MsÚ Ilona Almási na telefónom čísle 031-590 00 402. Žiadosti o dotáciu sa podávajú elektronicky a v písomnej forme na adresu: Mesto Šamorín, Hlavná 37, 931 01 Šamorín.",
            },
            {
                "locale": "hu",
                "title":"Új út",
                "description":"Attujitották az utat",

            },
            {
                "locale": "en",
                "title":"New wey",
                "description":"TThe way is new",
            }
        ],

I see this on web enter image description here

And my application when I read not see the serve data.

import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'app-posts2',
  templateUrl: './posts.component.html',
  styleUrls: ['./posts.component.scss'],
})
export class PostsComponent implements OnInit {

  posts:any = [];
  constructor(private http: HttpClient) { }



  ngOnInit() {


    const lang = localStorage.getItem('lang') || 'sk';

    const headers = new HttpHeaders({
      'Accept-Language': lang
    })


    this.http.get('https://miki83.pythonanywhere.com/', {
      headers: headers
    }).subscribe(data=>{
      console.log();
      this.posts = data;
       });
  }

}

The screenshot is not rendering properly -- could you check your web app error logs and let us what are the errors on the bottom of the file (most recent ones)?