Django在/

Django在/,django,django-urls,Django,Django Urls,我刚刚设置了一个django项目,但出现了一个错误: Request Method: GET Request URL: http://127.0.0.1/hello/ Django Version: 1.6.6 Exception Type: ImproperlyConfigured Exception Value: The included urlconf <function hello at 0x7f665a1e0320> doesn't have any patt

我刚刚设置了一个django项目,但出现了一个错误:

Request Method: GET
Request URL:    http://127.0.0.1/hello/
Django Version: 1.6.6
Exception Type: ImproperlyConfigured
Exception Value:    
The included urlconf <function hello at 0x7f665a1e0320> doesn't have any patterns in it
Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in url_patterns, line 369
Python Executable:  /usr/local/bin/uwsgi
Python Version: 2.7.6
views.py:

from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello, world!")
settings.py:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# SECURITY WARNING: keep the secret key used in production sexbbiv*#q44x+jdawuchyu_!$wd#f-p(hid2r*zrjvy6a6#bsoxbbiv*#q44x+jdawuchyu_!$wd#f-p(hid2r*zrjvy6a6#bsocret!
SECRET_KEY = '##############&'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'testsite.urls'

WSGI_APPLICATION = 'testsite.wsgi.application'

# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
我在谷歌上搜索过关于设置DEBUG\u TOOLBAR\u PATCH\u SETTINGS=False的信息,但没有帮助。有什么问题以及如何解决?

请勿将其用于视图模式:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^hello/', testsite.views.hello),
)

include()
用于从另一个模块/应用程序就地“包含”url配置。

错误很明显:它不是有效的url配置

要更正此问题,可以按如下方式执行:

# app/views.py
from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello, world!")
现在在该应用程序中创建一个名为
urls.py
的文件:

# app/urls.py
from django.conf.urls import url

from app import views

urlpatterns = [
    url(r'^$', views.hello, name='hello'),
]
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^hello/', include('app.urls')),
    url(r'^admin/', include(admin.site.urls)),
]
现在终于进入
站点/url.py

# app/urls.py
from django.conf.urls import url

from app import views

urlpatterns = [
    url(r'^$', views.hello, name='hello'),
]
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^hello/', include('app.urls')),
    url(r'^admin/', include(admin.site.urls)),
]