gpt4 book ai didi

python - 需要 'package' 参数来执行相对导入

转载 作者:行者123 更新时间:2023-12-02 23:24:16 25 4
gpt4 key购买 nike

我不确定是什么导致了这个错误,我想尝试从 Windows PowerShell 在 django 上运行,但我遇到了这个错误和问题。

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03D366A8>
Traceback (most recent call last):
File "D:\Python\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "D:\Python\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "D:\Python\lib\site-packages\django\core\management\base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "D:\Python\lib\site-packages\django\core\management\base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "D:\Python\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "D:\Python\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "D:\Python\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "D:\Python\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\Python\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "D:\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "D:\Python\courseworkupload\courseworkupload\urls.py", line 26, in <module>
url(r'^upload/', include('.upload.urls')),
File "D:\Python\lib\site-packages\django\conf\urls\__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "D:\Python\lib\importlib\__init__.py", line 121, in import_module
raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '.upload.urls'

这是在我运行 python manage.py runserver 之后完成的

对这个问题的任何帮助都会很棒

编辑:在下面添加树
C:.
│ db.sqlite3
│ manage.py

├───.idea
│ courseworkupload.iml
│ misc.xml
│ modules.xml
│ workspace.xml

├───courseworkupload
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ └───__pycache__
│ settings.cpython-35.pyc
│ urls.cpython-35.pyc
│ wsgi.cpython-35.pyc
│ __init__.cpython-35.pyc

└───upload
│ admin.py
│ apps.py
│ forms.py
│ models.py
│ tests.py
│ urls.py
│ views.py
│ __init__.py

├───migrations
│ __init__.py

├───templates
└───__pycache__
admin.cpython-35.pyc
forms.cpython-35.pyc
models.cpython-35.pyc
urls.cpython-35.pyc
views.cpython-35.pyc
__init__.cpython-35.pyc

最佳答案

include('.upload.urls')中的前导点导致问题。

假设 upload位于您的项目目录中(包含 manage.py 的目录),将其更改为 upload.urls应该管用。

url(r'^upload/', include('upload.urls')),

关于python - 需要 'package' 参数来执行相对导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40917319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com