首页 > 解决方案 > 没有名为 django.urls 的模块

问题描述

我正在尝试创建一个新模型,我将其命名为产品,我发现了您在下面看到的此错误消息

请注意,我的 django 版本是 1.8.7

##urls.py:

from django.contrib import admin
from mySecondGdgBlogs import views
from django.urls import include, path
from myGdgBlogs import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('writeafterme/',include('mySecondGdgBlogs.urlss')),
    path('htm/', views.htamal),
    path('dp/',views.dpmain)
]

##views.py:

from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def dbmain(request):
    data = ''
    return HttpResponse(data)

##models.py

from django.db import models
# Create your models here.
class Products(models.Model):
    name = models.CharField (max_length=20)
    price = models.IntegerField()
    type=models.CharField(max_length=20,choices=(
        ('S', 'Small'),
        ('M', 'Medium'),
        ('L', 'Large'),
    ))
    class Meta:
        db_table = 'Products'

我希望向我展示一个白页,但浏览器中的实际结果是:

No module named 'django.urls'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.7
Exception Type: ModuleNotFoundError
Exception Value:    
No module named 'django.urls'
Exception Location: /home/mohammed/PycharmProject/GdgProject/myGdgProject/myGdgProject/urls.py in <module>, line 7
Python Executable:  /usr/bin/python3
Python Version: 3.6.8
Python Path:    
[
'/home/mohammed/PycharmProject/GdgProject/myGdgProject',

 '/usr/local/lib/python3.6/dist-packages/pip-19.1.1-py3.6.egg',

 '/usr/lib/python36.zip',

 '/usr/lib/python3.6',

 '/usr/lib/python3.6/lib-dynload',

 '/home/mohammed/.local/lib/python3.6/site-packages',

 '/usr/local/lib/python3.6/dist-packages',

 '/usr/lib/python3/dist-packages'

]

标签: django-models

解决方案


推荐阅读