我正在尝试使用Python shell导入模型,但出现错误:
ModuleNotFoundError:没有名为“ rango”的模块
'rango',
这里是项目结构和错误的显示页面:https://imgur.com/a/WlfNzEN
views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
context_dict = {'boldmessage': "Crunchy, creamy, cookie, candy, cupcake!" }
return render(request, 'rango/index.html', context=context_dict)
models.py
from django.db import models
class Category(models.Model):
# Unique TRUE attr means the name must be unique - can be used as a primary key too!
name = models.CharField(max_length=128, unique=True)
def __str__(self):
return models.Model.__str__(self)
class Page(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
title = models.CharField(max_length=128)
url = models.URLField()
views = models.IntegerField(default=0)
def __str__(self):
return models.Model.__str__(self)
class user_session(models.Model):
userNAME = models.CharField(max_length=120, unique=True)
addToCarts = models.IntegerField(default=0)
def __str__(self):
# __unicode__ on Python 2
return self.headlin
答案 0 :(得分:1)
如果您的urls.py
与views.py
位于同一文件夹中,则可以尝试
from . import views
但是如果urls.py
在Tango文件夹中,请尝试
from ..rango import views
您还可以尝试重命名第一个Tango
文件夹吗,这里可能会出现错误
Tango/
Tango/
...
rongo/
Tango/
...
尝试将第一个Tango文件夹重命名为类似
Projects/
Tango/
...
rongo/
Tango/
...