尝试在Django中跟踪循环导入错误 [英] Trying to trace a circular import error in Django
问题描述
我知道有人问过很多循环导入错误,但是经过这些问题之后,我仍无法解决问题。当我尝试在Django中运行服务器时,它给我以下错误消息:
I understand circular import error has been asked about a lot but after going through these questions I haven't been able to solve my issue. When I try to run my server in Django its giving me this error message:
从path\to包含的URLconf模块'accounts_app' \myproject\__init __。py似乎没有任何模式。如果您在文件中看到有效的模式,则说明问题可能是由循环导入引起的。
The included URLconf module 'accounts_app' from path\to\myproject\__init__.py does not appear to have any patterns in it. if you see valid patterns in the file then the issue is probably caused by a circular import.
问题是我添加新的来自django.conf.urls的具有以下urls.py的应用
The issue started when i added a new app which has a urls.py like the following
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^signin$', views.signin, name='signin'),
url(r'^signout$', views.signout, name='signout'),
url(r'^signup$', views.signup, name='signup'),
]
我的项目urls.py中有一行指向应用程序,看起来像下面的代码
My project urls.py has a line which points to the app and looks like the following code
urlpatterns = [
url(r'^accounts/', include('accounts_app')),
]
我的视图如下:
from django.shortcuts import render
from django.http import HttpResponse
def signin(request):
return HttpResponse("<p>This the signin view</p>")
def signout(request):
return HttpResponse("<p>This the signout view</p>")
def signup(request):
return HttpResponse("<p>This the signup view</p>")
任何人都可以帮助我确定是我可能会出错。
Can anyone please help me identify were I could possibly be going wrong.
推荐答案
尝试更改
urlpatterns = [
url(r'^accounts/', include('accounts_app')),
]
至
urlpatterns = [
url(r'^accounts/', include('accounts_app.urls')), # add .urls after app name
]
这篇关于尝试在Django中跟踪循环导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!