Django AttributeError'tuple'对象没有属性'regex' [英] Django AttributeError 'tuple' object has no attribute 'regex'

查看:128
本文介绍了Django AttributeError'tuple'对象没有属性'regex'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 = [
#示例:
#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

 
hizlinot项目的Django设置

使用Django 1.8生成'django-admin startproject'

有关此文件的更多信息,请参阅
https://docs.djangoproject.com/en/1.8/topics/settings/

有关设置及其值的完整列表,请参阅
https://docs.djangoproject.com/en/1.8/ref/settings/


#在项目中构建路径,如下所示:os.path .join(BASE_DIR,。 ..)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__)))


#快速启动开发设置 - 不适合生产
#请参阅https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

#安全警告:保持秘密关键用于生产秘密!
SECRET_KEY ='b-4jipu5t(+)g(2-7g#s = 1rs19dhpj-1-!x1b- * v7s85f-m%& q'

#安全警告:在生产中打开调试程序运行
DEBUG = True

ALLOWED_HOSTS = []


#应用程序定义

INSTALLED_APPS =(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib。会话',
'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.MessageMi ddleware',
'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'


#数据库
#https:// docs .djangoproject.com / en / 1.8 / ref / settings /#databases

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


#国际化
#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


#静态文件(CSS,JavaScript,图像)
#https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL ='/ static /'


解决方案>

你忘了' url '

  url '^ 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


I'm using django 1.8 and having trouble with it. I am trying to import tinymce in my project. When I render it caught

AttributeError: tuple' object has no attribute 'regex'

When I remove the url in url.py it is working. Here is my codes.

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/'

解决方案

You forgot the 'url'

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

urlpatterns should be a list of url() instances

url returns RegexURLPattern but instead a tuple is found in your list.

https://docs.djangoproject.com/en/1.8/_modules/django/conf/urls/#url

这篇关于Django AttributeError'tuple'对象没有属性'regex'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆