When you create Web app + database via the portal it configures the database so that only incoming connections from the virtual network are permitted. This can't be changed after creation.
To connect to your Azure Database for PostgreSQL flexible server you need to connect from an IP on the virtual network. For example, if you had a VM on the same VNet you could SSH/RDP to it and then you would be able to connect to your database from within that VM.
Please click Accept Answer and upvote if the above was helpful.