Django: cannot import name

穿精又带淫゛_ 提交于 2019-12-05 03:37:54

You most likely had a circular import in the module LoginView was defined in, i.e. when you were importing the views module that defined LoginView, some statement somehow in turn imported some other module that was still waiting to get fully interpreted.

Here's an example to give you a better idea:

# myapp.urls

from django.conf.urls.defaults import *
from myapp import views

urlpatterns = patterns('',
    # ...
)

# myapp.views

from django.core.urlresolvers import reverse
from django.views.generic.edit import CreateView

class SomeCreateView(CreateView):

    # BOOM!
    success_url = reverse('myapp:some-url')

Once myapp.views gets imported and the SomeCreateView type gets allocated to memory, reverse('myapp:some-url') will get executed and your myapp.urls will eventually be imported by Django, only that that won't ever be possible since myapp.urls will indefinitely wait for myapp.views to get imported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!