xiaosi4081 发表于 2020-7-29 15:08:55

django报错

本帖最后由 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'

Twilight6 发表于 2020-7-29 15:10:31




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

xiaosi4081 发表于 2020-7-29 15:12:48

Twilight6 发表于 2020-7-29 15:10
发完整报错吧,别发你翻译后的

发了

Twilight6 发表于 2020-7-29 15:14:41

xiaosi4081 发表于 2020-7-29 15:12
发了


你用的是什么编辑器,电脑上有多个版本的 Python 吗?

xiaosi4081 发表于 2020-7-29 15:16:05

Twilight6 发表于 2020-7-29 15:14
你用的是什么编辑器,电脑上有多个版本的 Python 吗?

我的这个gam目录是用python的virtualenv环境弄的

Twilight6 发表于 2020-7-29 15:16:44

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




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


xiaosi4081 发表于 2020-7-29 15:20:29

Twilight6 发表于 2020-7-29 15:16
那就要去对应环境安装对应模块,和 Conda 类似

果真,就是pip是anaconda的(我电脑里的版本可真够多的:python3.8,anaconda),我改了下环境变量就好了

xiaosi4081 发表于 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.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.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, 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.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.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, 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'
页: [1]
查看完整版本: django报错