好的我是Django框架的新手,但我有一个我想要的基本网站。我在Digital Ocean上有一个小滴,我的文件已移到那里。
我收到此错误:
ImportError at /
cannot import name patterns
Request Method: GET
Request URL: http://188.166.147.202/
Django Version: 1.10.2
Exception Type: ImportError
Exception Value:
cannot import name patterns
Exception Location: /home/django/django_project/django_project/urls.py in <module>, line 1
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/django/django_project',
'/home/django',
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0']
Server time: Sun, 16 Oct 2016 16:26:46 +0000
urls.py看起来像:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('personal.urls')),
url(r'^blog/', include('blog.urls')),
]
doplet目前正在使用python 2.7,但我在开发时使用了python3,那么如何升级我的Droplet上的python版本呢?
答案 0 :(得分:2)
patterns
在Django 1.8中被弃用,在Django 1.10中被删除。
urlpatterns
已经是应有的,url()
个实例列表。只需将导入更改为:
from django.conf.urls import include, url