Python+django changed the urls.py after the Runserver error resolution

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.