Py学习  »  问与答

Django-1.8 Python2.7 写博客出错A server error occurred. Please contact the administrator.

Alan • 10 年前 • 10160 次点击  

http://127.0.0.1:8000/ 页面提示 A server error occurred. Please contact the administrator.

请问哪里出问题了??十分感谢

我的setting.py 的设置

Build paths inside the project like this: os.path.join(BASE_DIR, ...)

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

Quick-start development settings - unsuitable for production

See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = '474^_i#15!oh9cgrjb&gg&xz1ln6c*v0(n(6)um_k2wfc6w$9s'

SECURITY WARNING: don't run with debug turned on in production!

DEBUG = False

ALLOWED_HOSTS = ['*']

Application definition

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

)

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

)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]

WSGI_APPLICATION = 'mysite.wsgi.application'

Database

https://docs.djangoproject.com/en/1.8/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.8/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.8/howto/static-files/

STATIC_URL = '/static/'

template

TEMPLATE_DIRS=( '/home/fnngj/djpy/mysite/blog/templates', )

我的 urls设置 from django.conf.urls import patterns,include, url from django.contrib import admin

urlpatterns = patterns('', # Examples: # url(r'^$', 'mysite.views.home', name='home'),

url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),

)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1163
 
10160 次点击  
文章 [ 6 ]  |  最新文章 10 年前
shen_gan
Reply   •   1 楼
shen_gan    10 年前

@Alan 你试试这个:http://127.0.0.1:8000/blog/

URL / was not found 这个是因为你的 urls.py 中并没有对网站首页 "/" 解析。

Alan
Reply   •   2 楼
Alan    10 年前

@阿布 把debug打开变成这样了,晕,怎么弄都不行~ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^blog/ ^admin/ The current URL, , didn't match any of these.

Alan
Reply   •   3 楼
Alan    10 年前

@shen_gan

显示这个 Not Found

The requested URL / was not found on this server.

阿布
Reply   •   4 楼
阿布    10 年前

1.8的template模板路径位置不要再单独配置

在TEMPLATES里的DIRS添加路径如下:html改成你的路径

'DIRS': [os.path.join(BASE_DIR, 'html')],

很多种配置问题都有可能导致页面报错,把debug打开,看下详细的报错。

shen_gan
Reply   •   5 楼
shen_gan    10 年前

debug 可以打开吗?可以的话,打开再运行看看错误提示。

Alan
Reply   •   6 楼
Alan    10 年前

麻烦各位高手指点了