django_select2渲染时捕获NameError:未定义名称“模式”

时间:2013-10-31 07:59:49

标签: django

我在夹层项目中使用django_select2 按照文档,我遵循流程。

#step1 :
pip install django-select2
#Step2 :
url(r'^select2/', include('django_select2.urls')),

但是,当我重新加载我的网站时,我收到了错误

TemplateSyntaxError at /admin/cms_shop/deliverymethod/200/

Caught NameError while rendering: name 'patterns' is not defined

Request Method:     GET
Request URL:    https://example.net/admin/cms_shop/deliverymethod/200/
Django Version:     1.3.1
Exception Type:     TemplateSyntaxError
Exception Value:    

Caught NameError while rendering: name 'patterns' is not defined

Exception Location:     /home/django/cmsenv/lib/python2.6/site-packages/django_select2/urls.py in , line 5
Python Executable:  /home/django/cmsenv/bin/python
Python Version:     2.6.5
Python Path:    

['/home/django/core/python/cmsintegration',
 '/home/django/cmsenv/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg',
 '/home/django/cmsenv/lib/python2.6/site-packages/pip-0.8.3-py2.6.egg',
 '/home/django/cmsenv/lib/python2.6/site-packages/paython-0.0.1-py2.6.egg',
 '/home/django/cmsenv/lib/python2.6/site-packages/django_shop-0.0.11.dev0-py2.6.egg',
 '/home/django/cmsenv/lib/python2.6/site-packages/django_recaptcha-0.0.6-py2.6.egg',
 '/home/django/cmsenv/lib/python2.6',
 '/home/django/cmsenv/lib/python2.6/plat-linux2',
 '/home/django/cmsenv/lib/python2.6/lib-tk',
 '/home/django/cmsenv/lib/python2.6/lib-old',
 '/home/django/cmsenv/lib/python2.6/lib-dynload',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/home/django/cmsenv/lib/python2.6/site-packages',
 '/home/django/cmsenv/lib/python2.6/site-packages/PIL']

请帮助我,我做错了什么。 我的urls.py代码是

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns("",
    url(r'^admin/cms_shop/productimport/delete_selected/([\w]+)/$', delete_selected_import_view, name="cms_shop_delete_selected_import"),
    url("^admin/", include(admin.site.urls)),
    url(r'^select2/', include('django_select2.urls')), 
)

in settting.py

INSTALLED_APPS = (
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.redirects",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.sitemaps",
    "mezzanine.conf",
    "mezzanine.core",
    "mezzanine.blog",
    "mezzanine.pages",
    "mezzanine.generic",
    "userapp",
    "django_select2",
)

2 个答案:

答案 0 :(得分:16)

仅供参考,你有Django 1.3,应该考虑升级到1.5。

你试过吗

from django.conf.urls import patterns

答案 1 :(得分:5)

如果要升级到Django 1.8或更高版本,则会出现此错误。

以下是没有模式的新方法:

https://docs.djangoproject.com/ja/1.9/releases/1.8/#s-django-conf-urls-patterns

urlpatterns = [
    url('^$', views.myview),
    url('^other/$', views.otherview),
]