试图在 Django 中跟踪循环导入错误 [英] Trying to trace a circular import error in Django

查看:30
本文介绍了试图在 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:

路径 omyproject\__init__.py 中包含的 URLconf 模块accounts_app"似乎没有任何模式.如果您在文件中看到有效模式,则问题可能是由循环导入引起的.

The included URLconf module 'accounts_app' from path omyproject\__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.

当我添加一个新的应用程序时,问题就开始了,该应用程序的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆