【发布时间】:2020-07-17 13:08:39
【问题描述】:
当我在绝对路径名中运行命令 python manage.py test 时出现此错误 C:\Users\vitorfs\Development\myproject\myproject 在我通过在 Windows 上选择以管理员身份运行打开的命令行上。在boards.py中,我有以下内容
from django.core.urlresolvers import reverse
from django.test import TestCase
class HomeTests(TestCase):
def test_home_view_status_code(self):
url = reverse('home')
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
这是我得到的错误:
1. Failed to import test module: board.tests. 2. ModuleNotFoundError: No module named django.core.urls
我无法修复错误。我按照https://simpleisbetterthancomplex.com/series/2017/09/11/a-complete-beginners-guide-to-django-part-2.html 上的 Django 教程进行操作@
你能告诉我这意味着什么并帮助我解决这个错误吗?
只是为了让你知道,我学习 Python 和 Django 是为了好玩。
【问题讨论】:
-
这可能是由于教程已过时。对于您的 python/django 版本,您应该使用
from django.urls import reverse。如果你把错误代码放在这里而不是截图也很好。 -
好的 - 所以截图告诉我的错误是 1. 导入测试模块失败:board.tests。 2. ModuleNotFoundError: No module named django.core.urls Ehsan88
-
我通过将 django.core.urlresolvers import reverse 更改为 django.urls import reverse 来修复错误。有用。谢谢,Ehsan88。