In most of Brazil, a 'd' followed by 'i' is pronounced as 'dji': 'djia' (dia), 'rádjio' (rádio).
When the 'd' is followed by a 'e' in the end of the word, it is also pronounced as 'dji': 'dji' (de), 'redji' (rede). But not in the middle of a word: depois, deus, idéia are all pronounced with a hard 'd'.
The same applies to the letter 't', pronounced as 'tch' under the same rules: 'leitchi' (leite), 'dentchi' (dente), 'tchirar' (tirar); 'terra' and 'tempo' with a hard 't'.
Of course, there are countless exceptions. In a lot of places (usually in the border with other countries, or in places recently colonized by europeans) these rules don't apply, and even where they do, there are a lot of words pronounced differently (for example I pronounce 'desculpa' as 'djisculpa'). If you follow these rules, or even if you pronounce always a hard 't' and 'd', you will be understood everywhere. Only with practice you will learn this details!
EDIT: look at my reply to this comment.
After reading this again, and thinking about it, I came to a better rule. (This pronounciation is from Porto Alegre, but valid in most of Brazil)
'di' is always pronounced 'dji';
'ti' is always pronounced 'tchi';
'de' is pronounced: 'de' if it is a tonic syllable, and there's no general rule if it is not tonic (can be 'de' or 'dji');
'te' is pronounced: 'te' if tonic, and no general rule if not tonic (can be 'te' or 'tji');
If you're not that worried about local accents, you can pronounce always the hard 'd' and 't'. I believe this is the way the european speak.
There is a lot of regional variation in the way things are pronounced in Brazil. For example in Rio their "s" sounds like "sh" so they all sound like they have lisps. I believe the pronunciations on this site are the most common (even though she sometimes sounds like a robot). For the "de" sound, it was explained to me as being similar to the "dg" sound in the word "judge"so basically like a hard g. But there are some places in Brazil where it is pronounced like in Spanish. Also this only applies to "de" like in "onde" but not "da" or "do" which have a normal english "d" sound. Hope this wasn't too confusing!
I translated this with "He likes cake from carrots" and Duolingo marked it as wrong. So there is no other word for "carrot cake" in Portuguese (meaning the actual translation for carrot cake is "cake from carrots")? Would be nice if someone could clarify this for me. In my native tongue "cake from carrots" and "carrot cake" are not neccessarily the same. I tried to look it up but came up with nothing. Apparently our dictionaries don't deem "carrot cake" worthy of their attention ;-)
In portuguese, in culinary we use "de" to say that the food contains an ingredient, even if it is not the most important. For example, "bolo de cenoura" is made of flour (as almost every other cake), but contains carrots as the different ingredient. So "bolo de cenoura", "bolo de laranja" and "bolo de chocolate" are all made from flour with a little bit of something different, and that different part is giving the name. The same rule applies to almost any food: "omelete de queijo" is made WITH cheese, not FROM cheese; "pastel de frango" is made WITH chicken, not FROM chicken. You could substitute "de" to "com", to grasp the meaning: "bolo com cenoura", "omelete com queijo", "pastel com frango".