解决django的No module named 'django.urls' 错误

  • 问题描述

    使用django搭建web服务时,运行python manage.py runserver后出现 No module named ‘django.urls’ 错误

  • 环境:

    python3.5
    Django==1.10

  • 原始代码:

from django.conf.urls import patterns, include, url

from image.views import ImageView

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

urlpatterns = patterns('',
    url(r'', ImageView.as_view(), name='image'),
    # Examples:
    # url(r'^$', 'image_upload.views.home', name='home'),
    # url(r'^image_upload/', include('image_upload.foo.urls')),

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

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)
  • 修改后代码:
from django.conf.urls import url

from image.views import ImageView

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

urlpatterns = [
    url(r'', ImageView.as_view(), name='image'),
    # Examples:
    # url(r'^$', 'image_upload.views.home', name='home'),
    # url(r'^image_upload/', include('image_upload.foo.urls')),

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

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
]
  • 分析原因:
    django版本不兼容导致的

你可能感兴趣的:(模型部署,常见问题)