我正在研究一个django项目并面临一个问题。我的主项目名称是testproject。在 settings.py 中,我有:
ROOT_URLCONF = 'testproject.urls'
项目中也有两个应用程序。一个是示例,另一个是新。
testproject的urls.py :
from django.conf.urls import include, url
urlpatterns = [
url(r'', include('new.urls')),
url(r'', include('example.urls')),
]
这是示例的 urls.py :
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from example import views
urlpatterns = [
url('example/$', views.Example.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
这是 new的 urls.py :
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from new import views
urlpatterns = [
url('new/$', views.New.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
点击url" 127.0.0.1:8000 / example"我收到了错误:
ImproperlyConfigured at /example/
The included urlconf '<module 'new.urls' from '/Users/testproject/name/urls.pyc'>' 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.
但我在这里看不到任何循环进口。我被卡住了。请帮帮我。
答案 0 :(得分:0)
在项目的urls.py中尝试:
urlpatterns = [
url(r'^new/$', include('new.urls')),
url(r'^example/$', include('example.urls')),
]
在示例中的urls.py:
urlpatterns = [
url(r'^$', views.Example.as_view()),
]
最后一个:
urlpatterns = [
url(r'^$', views.New.as_view()),
]