首页 > 解决方案 > 我有一个关于运行 python manage.py test 的命令行的 Django 问题

问题描述

当我在命令行上以绝对路径名 C:\Users\vitorfs\Development\myproject\myproject 运行命令 python manage.py test 时出现此错误,我通过在 Windows 上选择 Run as Admin 打开该命令行。在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 是为了好玩。

标签: pythondjango

解决方案


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

按着这些次序:

在您的命令提示符中- 在您的命令提示符中- # 假设您使用 django 2.7pip uninstall django
pip install django==2.7

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

推荐阅读