when a novice learns Python+django, the urls.py is changed to:From django.conf.urls import patterns, include, url
From Django.contrib Import admin
Admin.autodiscover ()
Urlpatterns = Patterns ("',
# Examples:
# URL (R ' ^$ ', ' mysite.views.home ', name= ' home '),
# URL (R ' ^blog/', include (' Blog.urls ')),
URL (r ' ^admin/', admin.site.urls),
URL (r ' ^$ ', ' mysite.views.first_page '),
)
Enter MySite and start the server:
Python manage.py Runserver 8000
But error:importerror:cannot import Name Patterns
This is because: after the 1.10 django patterns was removed, there is no such module.
The first step, I will firstFrom django.conf.urls import patterns, include, url
Change into
From django.conf.urls import include, urltry again, or you'll get an error:Typeerror:view must be a callable or a list/tuple in the case of include ()
The second step, since reported this mistake, then I add include () Bai, so will
URL (r ' ^admin/', admin.site.urls),
URL (r ' ^$ ', ' mysite.views.first_page '),
Change into
URL (r ' ^admin/', include (Admin.site.urls)),URL (r ' ^$ ', include (' Mysite.views.first_page ')),
Again run try, and error:importerror:not module names ' Mysite.views.first_page '; Mysite.views ' isn't package
What do you do?
The third step, can only go to Fqgoogle, the best solution is this, delete the include package and import the Mysite.views package:
From Django.conf.urls import URL
From Django.contrib Import admin
From MySite Import views
Urlpatterns = [
URL (r ' ^admin/', admin.site.urls),
URL (r ' ^$ ', views.first_page)
]
Python+django changed the urls.py after the Runserver error resolution