所以我开始使用Django但是我在尝试运行服务器时遇到了一些问题。
我安装了两个版本的python。所以在我的mysite包中我尝试运行python manage.py runserver
但是我收到了这个错误:
Unhandled exception in thread started by <function wrapper at 0x058E1430>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Davide\Desktop\django-proj\mysite\mysite\urls.py", line 17, in <module>
from django.urls import path
ImportError: cannot import name path
是因为我安装了两个版本吗?
答案 0 :(得分:3)
不确定您目前正在使用的django版本,但如果您正在使用Django 2.0,那么python2将无法正常工作(因为Django2.0仅支持Python 3.4 +)
所以在你的情况下,如果你在Django2.0(假设你已经在你的机器上安装了最新版本的python),那么你应该运行以下命令。
python3 manage.py runserver
或者在虚拟环境中安装python3而不是python2。希望你的命令
python manage.py runserver
将完美运作。
答案 1 :(得分:0)
您是否尝试过通过pip或pip3升级django?
pip install --upgrade django --user
答案 2 :(得分:0)
您需要升级 Django
pip install --upgrade django
pip3 install --upgrade django