The position of those pronouns before or after the verb is given by the rules which are in the section 3 of this link of RAE.
A quick summary of what RAE says in that link:
They have to go before the verb:
- with verbs in indicative mood (it's archaic to place them after the verb):
- with verbs in subjuctive mood (for non exhorting verbs)
They have to go after the verb:
- with verbs in imperative mood
- with verbs in subjuctive mood (for exhorting verbs)
- with verbs in infinitive or gerund (in verbal periphrasis it usually can be placed also before).
In your example you are using the verb dar in the indicative mood. For that reason those pronouns should be placed before the verb. So the correct one would be:
La maestra nos lo da.
You have to take into account that the word "da" can be a present of indicative but also an imperative:
(Él/Ella) da - present of indicative
da (tú) - imperative
So if you place the pronouns after the verb then people would think you are using imperative:
Nos lo da --> He gives it to us
Dánoslo --> Give it to us. (imperative)
So yor second sentence:
La maestra dánoslo* (Incorrect)
would be incorrect because you can't use "la maestra" with an imperative.