On 9/08/2013 4:13am, JJ Zolper wrote:
> Hello everyone,
>
> I've only been working with Python and Django for a couple of years now
> and whenever I can I like to learn more about certain rationalizations
> for certain decisions made within each of them.
>
> In Django we define a Python class with a name to represent our model (I
> think it's a python class at least) and then we write "def" for
> definition of a view function or python function. To me I view this as
> two separate types of structures and thus fairly often I give a model
> the same name as a view. It isn't until later that I realize that my app
> isn't working because of the fact that they have the same name. I'm here
> just wondering if anyone would be willing to explain how this comes
> about from how Python/Django treats this instance? Why does Django see a
> confliction between a class and a function with the same name? Aren't
> they entirely separate entities?
>
> I'm by all means okay with going in and changing the names of the view
> or model to something slightly different so everything works, I just
> would like to understand conceptually why it is an issue?
Python uses namespaces a lot including inside a package, module, class
and inside a def and if you bring two objects with the same name into
the same namespace things will break.
However, you can do it if you don't import the object but instead
preface it with its namespace. For example: foo(a model) and views.foo(a
view)
Google for python namespace and you should see some good info.
hth
>
> Thanks a lot,
>
> JJ Zolper
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment