包含其他url文件的错误配置错误

时间:2017-08-02 15:31:48

标签: python django django-rest-framework

我正在使用django-cookiecutter来引导我的项目,其中包括api路径。按照Two Scoops of Django 1.11中的步骤配置我的网址遵循与此类似的模式:

   api/foo_app/ # GET, POST
   api/foo_app/:uuid/ # GET, PUT, DELETE
   api/bar_app/ # GET, POST
   api/bar_app/:uuid/ # GET, PUT, DELETE

当我尝试像这样设置我的项目时,我收到以下错误: django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'my_project.core.api_urls' from /Users/username/Development/my_project/my_project/core/api_urls.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.

我目前的设置:

my_project.config.settings.base.py

ROOT_URLCONF = 'config.urls'
DJANGO_APPS = [
    # Default Django apps:
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Useful template tags:
    # 'django.contrib.humanize',

    # Admin
    'django.contrib.admin',
]
THIRD_PARTY_APPS = [
    'crispy_forms',  # Form layouts
    'allauth',  # registration
    'allauth.account',  # registration
    'allauth.socialaccount',  # registration
    'rest_framework',
]

# Apps specific for this project go here.
LOCAL_APPS = [
    # custom users app
    'my_project.users.apps.UsersConfig',
    'my_project.core.apps.CoreConfig',
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

my_project.config.urls.py

from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views

urlpatterns = [
    url(r'^users/', include('my_project.users.urls', namespace='users')),
    url(r'^api/', include('my_project.core.api_urls', namespace='api')),
]

my_project.core.api_urls.urls

from django.conf.urls import url
from django.views.defaults import page_not_found

urlpattenrs = [
    url(
        regex=r'^users/$',
        view=page_not_found,
    ),
]

core应用目前不包含任何模型。这就是我组织所有网址的地方

1 个答案:

答案 0 :(得分:0)

“urlpattenrs”应该是“urlpatterns”(在my_project.core.api_urls.urls中);)