2013-10-31 31 views
4

我正在使用django_select2和我的夾層項目。
按照文檔我遵循過程。django_select2在呈現時捕獲NameError:名稱'patterns'未定義

 
#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')), 
) 
在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", 
) 

回答

16

僅供參考,你的Django 1.3,應該考慮升級到1.5。

你試過

from django.conf.urls import patterns 
+0

感謝保羅。但我無法將我的項目升級到1.5。我如何使用django-select2與django1.3.1 –

+0

@Sonu,夠公平的。我不確定django-select2是你的問題。你的錯誤沒有堆棧跟蹤嗎? –

+0

是的,我遇到了問題。 django-select2只需要Django 1.4或以上版本。這就是爲什麼我要求你幫助我 –