【问题标题】:Unhandled exception in thread started by <function wrapper at 0x7f39d480f230><function wrapper at 0x7f39d480f230> 启动的线程中未处理的异常
【发布时间】:2018-12-26 05:19:22
【问题描述】:

我的 Django 项目中出现以下错误:

Traceback (most recent call last):
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check(display_num_errors=True)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/freddy/environments/py26_env/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/freddy/environments/balog/balog/urls.py", line 18, in <module>
    from django.urls import include, path
ImportError: cannot import name include

我正在使用:

>>> python -m django --version
1.11.14
>>> python --version
Python 2.7.15rc1

【问题讨论】:

标签: python django


【解决方案1】:

Django 1.11 不使用path(在 Django 2 中添加)。您需要使用urlinclude 位于同一个地方。

from django.conf.urls import include, url

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    相关资源
    最近更新 更多