无法在Django中导入模式

塔曼·马利克(Tameen Malik)

我在Django url.py文件中定义url。每当我在浏览器中放置url并运行它时,它说:

cannot import name patterns
Request Method: GET
Request URL:    http://127.0.0.1:8000/accounts/
Django Version: 1.2.4
Exception Type: ImportError
Exception Value:    
cannot import name patterns
Exception Location: C:\Python27\lib\site-packages\registration\backends\default\urls.py in <module>, line 20
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.1
Python Path:    ['C:\\Users\\Tameen\\lmn', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL']
Server time:    Thu, 20 Mar 2014 17:17:58 +0500

我的Url.py文件是:

    from django.conf.urls.defaults import *

 Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    (r'^accounts/', include('registration.backends.default.urls')),
    (r'^admin/', include(admin.site.urls)),
    (r'^pastebin/', include('pastebin.urls')),
    (r'^blog/', include('blog.urls')),
    # Example:
     (r'^lmn/', include('lmn.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     #(r'^admin/', include(admin.site.urls)),
    )
蒂米·奥马尼(Timmy O'Mahony)

您正在使用django-registration(1.0)的最新版本和(1.2)的(非常)旧版本django在其中django-registration使用以下代码urls.py

from django.conf.urls import patterns

在您的django版本中,

from django.conf.urls.defaults import patterns

您有两种选择:

  1. 升级您的Django版本如果您正在使用pip,则可以执行以下操作:pip install django==1.6
  2. 降级您的django-registration如果您使用pip,则可以这样做pip install django-registration==0.8(或者可以达到0.7)

显然第一个选项是首选,因为1.2是一个非常老的Django版本

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章