Friday, June 19, 2015

Re: Inconsistency when importing views and models

On 20/06/2015 11:01 AM, jorrit787@gmail.com wrote:
> This is mostly a cosmetic question, and I could be completely wrong
> because I'm fairly new to Django, or it could be that there is a
> perfectly logical explanation for this, but here goes:
>
> It seems the code required to import views in urls.py and models in
> views.py is inconsistent (and in the case of urls.py perhaps redudant).

Not really. It is pure Python and nothing to do with Django.

It depends on your project layout. For example, is models a directory or
a file?

Where is views.py?

Are you using absolute_import or relative import?

How does it work from within Python running in a terminal?

If things work inconsistently it probably means you are successfully
importing something which is on sys.path which you didn't expect.

hth

Mike
>
> To import views in urls.py I have to use
>
> |
> from<appname>importviews
> |
>
> ...while in views.py I can simply write
>
> |
> frommodels import*
> |
>
> Why do I need to reference the appname in urls.py but not in views.py?
> Or is there a reason for this?
>
> --
> 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
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/03eb4740-6503-4757-ae09-9183ac2b8502%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/03eb4740-6503-4757-ae09-9183ac2b8502%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5584C7D2.3030401%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment