【问题标题】:I have a Django Question regarding the command line regarding running python manage.py test我有一个关于运行 python manage.py test 的命令行的 Django 问题
【发布时间】: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。

标签: python django


【解决方案1】:

重新安装 django 是唯一的选择,因为您的 core 实用程序已损坏

按照以下步骤操作:

在您的命令提示符下 - pip uninstall django
在您的命令提示符中 - pip install django==2.7 # 假设您拥有 django 2.7

也许这会有所帮助,如果还有其他问题,请告诉我我支持你!

【讨论】:

  • Django 的版本不同。
  • Aryan,你能告诉我如何解决我在使用 Django 时遇到的问题吗?
猜你喜欢
  • 1970-01-01
  • 2016-08-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-11
  • 2021-05-20
相关资源
最近更新 更多