无法导入名称模式 [英] cannot import name patterns
本文介绍了无法导入名称模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我写 urls.py
之前,我的代码...一切都工作正常。现在,我遇到了问题-无法访问我的网站。 无法导入名称模式
Before I wrote in urls.py
, my code... everything worked perfectly. Now I have problems - can't go to my site. "cannot import name patterns"
我的 urls.py
是:
from django.conf.urls import patterns, include, url
他们说这里有什么错误。
They said what error is somewhere here.
推荐答案
您不需要这些导入。 urls.py(开始)中唯一需要的是:
You don't need those imports. The only thing you need in your urls.py (to start) is:
from django.conf.urls.defaults import *
# This two if you want to enable the Django Admin: (recommended)
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
# ... your url patterns
)
注意:该解决方案适用于Django< 1.6。这实际上是Django本身生成的代码。有关较新的版本,请参见Jacob Hume的答案。
NOTE: This solution was intended for Django <1.6. This was actually the code generated by Django itself. For newer version, see Jacob Hume's answer.
这篇关于无法导入名称模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文