Friday, January 27, 2017

Re: Am I stupid or is there an essential error in Django 1.10 Docs?

But if I do a direct import via python's import statement. it will execute the content of the file before loading apps and that raises that error.
No matter what you import you have to use django's import system. Also it just works fine now.

Am Dienstag, 17. Januar 2017 23:05:10 UTC+1 schrieb Vijay Khemlani:
The only "custom include" in Django is for loading other url files

The rest of the imports are typical Python module / packages

On 1/17/17, 'Peter Müller' via Django users
<django...@googlegroups.com> wrote:
> Ah I now see the problem. However I tried to remove the entry in the
> __init__.py file
> Python is then unable to find *any *module in that directory. Don't ask me
> why that is.
>
> Also I noticed that django has its completely own import ecosystem.
> So I used django.conf.urls.include to include a new urls file in that sub
> directory.
> And suddenly everything works fine.
>
> Thanks everyone
>
> Am Dienstag, 17. Januar 2017 08:01:41 UTC+1 schrieb Michal Petrucha:
>>
>> On Mon, Jan 16, 2017 at 12:23:09PM -0800, 'Peter Müller' via Django users
>>
>> wrote:
>> > Am Montag, 16. Januar 2017 21:20:53 UTC+1 schrieb Daniel Roseman:
>> > > The traceback shows that you are importing your views module in the
>> > > __init__.py of your app. Don't do that.
>> >
>> > Well else python doesn't find the view.py file?
>>
>> Python will be able to import db_testing.views just fine even if you
>> don't import viewsi from . in db_testing/__init__.py. All Python cares
>> about is that there is a correct Python file in the correct location.
>>
>> If you're interested in more details about what's going wrong here,
>> there's an explanation here:
>>
>> https://docs.djangoproject.com/en/1.10/ref/applications/#how-applications-are-loaded
>>
>>
>> In particular, the following paragraphs:
>>
>> > At this stage, your code shouldn't import any models!
>> >
>> > In other words, your applications' root packages and the modules
>> > that define your application configuration classes shouldn't import
>> > any models, even indirectly.
>>
>> What's happening here is that the root of your "db_testing" package
>> (i.e. db_testing/__init__.py) indirectly imports models, because it
>> imports the views module, which in turn imports models.
>>
>> Just removing the "from . import views" line should let you move
>> forward – unless you also have other imports in the __init__.py file,
>> in which case you can most likely just remove them, too. In general,
>> in an average Django package, there's little reason to import stuff in
>> its root package.
>>
>> Good luck,
>>
>> Michal
>>
>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b1760656-c6a0-40c5-a002-19958e5706ef%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d45b367-bed9-4181-80c0-d07b82d35df3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment