我是Django的新手,想弄清楚Django的网址是如何工作的。Django 1.6网址不能正常工作
我的应用程序的urls.py
from django.conf.urls import url, patterns
import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'))
项目urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^app/', include('app.urls')),
)
APPEND_SLASH = True
在settings.py
和应用设置包含在INSTALLED_APPS。
我得到页面未找到当我去localhost:8000/app
。
现在我不能去localhost:8000/admin
也。
RuntimeError at /admin/
maximum recursion depth exceeded
应用程序的views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("This is Hello")
Settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
APPEND_SLASH = True
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'bfa&y-8d4^c&6a4hqz^am^1-xce05oj6&_$n!t=$v10fka(-!w'
# 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',
'django.contrib.admin',
'app',
)
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 = 'appmain.urls'
WSGI_APPLICATION = 'appmain.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
什么,我做错了。请帮忙。
不能当场什么不妥。您的应用是否在设置INSTALLED_APPS中?你能发布views.index吗? – allcaps
您是否将'APPEND_SLASH'设置为'False'?如果是这种情况,您需要转到'localhost:8000/app /' – sk1p
您是否安装了CommonMiddleware?或改变了'APPEND_SLASH'? https://docs.djangoproject.com/en/dev/ref/settings/#append-slash – iurisilvio