鱼C论坛

 找回密码
 立即注册
查看: 1239|回复: 7

[已解决]django报错

[复制链接]
发表于 2020-7-29 15:08:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 xiaosi4081 于 2020-7-29 15:12 编辑
from django.conf.urls import url
import views
urlpatterns = [
    url(r"^$",views.hello)
]

报错:
Traceback (most recent call last):
  File "d:/gam/myproject/myproject/urls.py", line 17, in <module>
    import views
  File "d:\gam\myproject\myproject\views.py", line 1, in <module>
    from django.http import HttpResponse
ModuleNotFoundError: No module named 'django'

Traceback (most recent call last):
  File "d:\gam\myproject\myproject\urls.py", line 16, in <module>
    import django
ModuleNotFoundError: No module named 'django'


最佳答案
2020-7-29 15:16:44
xiaosi4081 发表于 2020-7-29 15:16
我的这个gam是用virtualenv环境弄的




那就要去对应环境安装对应模块,和 Conda 类似


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-29 15:10:31 | 显示全部楼层



发完整报错吧,别发你翻译后的

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-7-29 15:12:48 | 显示全部楼层
Twilight6 发表于 2020-7-29 15:10
发完整报错吧,别发你翻译后的

发了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-7-29 15:14:41 | 显示全部楼层


你用的是什么编辑器,电脑上有多个版本的 Python 吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-7-29 15:16:05 | 显示全部楼层
Twilight6 发表于 2020-7-29 15:14
你用的是什么编辑器,电脑上有多个版本的 Python 吗?


我的这个gam目录是用python的virtualenv环境弄的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-7-29 15:16:44 | 显示全部楼层    本楼为最佳答案   
xiaosi4081 发表于 2020-7-29 15:16
我的这个gam是用virtualenv环境弄的




那就要去对应环境安装对应模块,和 Conda 类似


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-7-29 15:20:29 | 显示全部楼层
Twilight6 发表于 2020-7-29 15:16
那就要去对应环境安装对应模块,和 Conda 类似

果真,就是pip是anaconda的(我电脑里的版本可真够多的:python3.8,anaconda),我改了下环境变量就好了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-7-29 15:23:12 | 显示全部楼层
Twilight6 发表于 2020-7-29 15:16
那就要去对应环境安装对应模块,和 Conda 类似

可装完模块(版本对应的)还是报错:
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "c:\users\x4\appdata\local\programs\python\python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "c:\users\x4\appdata\local\programs\python\python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "D:\gam\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "D:\gam\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "D:\gam\lib\site-packages\django\core\management\base.py", line 392, in check
    all_issues = self._run_checks(
  File "D:\gam\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "D:\gam\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "D:\gam\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "D:\gam\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 407, in check
    for pattern in self.url_patterns:
  File "D:\gam\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "D:\gam\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
    return import_module(self.urlconf_name)
  File "c:\users\x4\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\gam\myproject\myproject\urls.py", line 17, in <module>
    import views
ModuleNotFoundError: No module named 'views'

(gam) D:\gam\myproject>pip install django
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: django in d:\gam\lib\site-packages (3.0.8)
Requirement already satisfied: sqlparse>=0.2.2 in d:\gam\lib\site-packages (from django) (0.3.1)
Requirement already satisfied: asgiref~=3.2 in d:\gam\lib\site-packages (from django) (3.2.10)
Requirement already satisfied: pytz in d:\gam\lib\site-packages (from django) (2020.1)

(gam) D:\gam\myproject>manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "c:\users\x4\appdata\local\programs\python\python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "c:\users\x4\appdata\local\programs\python\python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "D:\gam\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "D:\gam\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "D:\gam\lib\site-packages\django\core\management\base.py", line 392, in check
    all_issues = self._run_checks(
  File "D:\gam\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "D:\gam\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "D:\gam\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "D:\gam\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 407, in check
    for pattern in self.url_patterns:
  File "D:\gam\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "D:\gam\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\gam\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
    return import_module(self.urlconf_name)
  File "c:\users\x4\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\gam\myproject\myproject\urls.py", line 17, in <module>
    import views
ModuleNotFoundError: No module named 'views'
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-19 17:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表