The point is that to get the partition function you have to sum over all states, with the usual Boltzmann weight factor $e^{-\beta E}$.
If you label the energy eigenstates of your system with $| n \rangle$ then the partition function will have the form $$ \tag{1} Z = \sum_n g_n e^{-\beta E_n},$$ where $E_n$ is the energy of the $n$-th state, and $g_n$ is a possibly present degeneracy factor counting the number of states with energy $E_n$ (which in the non-degenerate case is equal to 1 and thus unnecessary).
If you are dealing with a many-particles system one way to label the states is by specifying the configuration $\{ n_j\}_j$, i.e. the occupation number $n_j$ of the $j$-th particle, for every particle $j=1,...,N$, and the partition function can accordingly be written as $$ \tag{2} Z= \sum_{\{n_j\}} g(\{n_j\}) e^{-\beta E(\{n_j\})}, $$ where it is important to notice that the energy $E$ depends on the configuration $\{n_j\}$. However, while (2) is usually more practical in these circumstances, one could equally well express the partition function in the form (1).
Does this answer your question?