python - Django, where to import your modules -


i thought ok import of modules @ top of view file. if ever change model name can edit import @ top , not go digging through every view function need imported in.

well, ran instance had imported model @ top of view file, , used in function, reason django threw unbound variable error when tried use model query, leads me believe need imports each function?

so, question is, proper way it? import @ top of file or in each function needed.

thanks

there no requirement in django import modules @ function scope. can, true of python generally. i'd see code , error message. don't think problem due cause attribute to.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -