我正在使用 django 1.8 并遇到问题。我想在我的项目中导入tinymce。当我抓住它时
AttributeError:tuple'对象没有属性'regex'
当我删除url.py中的url时,它正在运行。这是我的代码。
url.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
# Examples:
# url(r'^$', 'hizlinot.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
(r'^tinymce/', include('tinymce.urls')),
]
settings.py
"""
Django settings for hizlinot project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# 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 = 'b-4jipu5t(+)g(2-7g#s=1rs19dhpj-1-!x1b-*v7s85f-m%&q'
# SECURITY WARNING: don't run with debug turned on in production!
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',
'edebiyat',
'tinymce',
)
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 = 'hizlinot.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 = 'hizlinot.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/'
答案 0 :(得分:52)
您忘记了'url
'
url(r'^admin/', include(admin.site.urls)),
url(r'^tinymce/', include('tinymce.urls')),
urlpatterns应该是url()实例列表
url
会返回RegexURLPattern
,但会在您的列表中找到元组。
https://docs.djangoproject.com/en/1.8/_modules/django/conf/urls/#url
答案 1 :(得分:4)
我知道这与问题并不完全相关,但有时这个错误可能比直接在 urls.py 文件中更深。
我收到此错误,问题的原因不在错误堆栈跟踪中。
我在使用自定义管理类浏览管理员时出现此问题,问题出在此类的方法 get_urls(),它返回的内容如下:
def get_urls(self):
from django.conf.urls import patterns
return ['',
(r'^(\d+)/password/$',
self.admin_site.admin_view(self.user_change_password))] + super(CompanyUserAdmin, self).get_urls()
修复它:
def get_urls(self):
from django.conf.urls import patterns
return [
url(r'^(\d+)/password/$',
self.admin_site.admin_view(self.user_change_password))] + \
super(CompanyUserAdmin, self).get_urls()
不要忘记导入'url':
from django.conf.urls import url