Density functional theory for nonuniform polymers: Accurate treatment of the effect of attractive interactions