我正在用Django的书学习Django。我在我的MacBookPro上用Mavericks 10.9运行python3.3.3,当我启用管理站点时,我得到“发生了一个服务器错误”。请与管理员联系。在浏览器中,来自Django服务器的“AttributeError:'RegexURLResolver'对象没有属性'\u urlconf_module'”错误。我已经检查(并寄出)我的设置.py以及网址.py没有发现任何问题。。。在
{我不相信这和我发现的一样。我认为这可能是一个特立独行的问题,所以我运行了所有的brew更新和django的pip升级,但我仍然收到这个错误。。。在
有什么想法吗?在
Porta-PuterTwo:LearningDjango arana$ python3 manage.py runserver
Validating models...
0 errors found
December 03, 2013 - 21:42:20
Django version 1.6, using settings 'LearningDjango.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/core/urlresolvers.py", line 339, in urlconf_module
return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/core/handlers/base.py", line 101, in get_response
resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python3.3/site-packages/django/core/urlresolvers.py", line 318, in resolve
for pattern in self.url_patterns:
在网址.py公司名称:
^{pr2}$在设置.py公司名称:
"""
Django settings for LearningDjango project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# 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 = '#6wow&islp6!6@+$9b%j9@981k^@i_uf8^=u%7gp@0b_^j^6t9'
# 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.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
'books',
)
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 = 'LearningDjango.urls'
WSGI_APPLICATION = 'LearningDjango.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'),
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'EST'
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/'
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
)
解决方案,在我看来很奇怪,是我指定根文件夹作为导入的开始书籍.模型在视图.py文件。这似乎不仅破坏了管理启动,而且它给出的错误没有给出太多(如果有的话)根问题的指示。直到我回退到Python2.7时,错误消息才告诉我问题的根源。 我猜这是典型的新手资料,因为现在看来很明显,网站的“根”应该是管理.py因此不应该在任何路径规范中。虽然这本书似乎没有说。。。在
我在尝试运行驻留在django项目之外的测试模块时遇到了这个错误(django似乎不支持这种做法):
这个错误是由django在进程的不同点假设不同的导入路径引起的,所以我通过添加到
sys.path
来解决这个问题。对于在生产环境中执行此操作,我可能会犹豫不决,但我可以接受测试中的一些黑客行为。在以下是我在^{中得到的结论:
^{pr2}$相关问题 更多 >
编程相关推荐