Django教程1

时间:2015-12-09 16:00:55

标签: python django python-2.7

我开始学习Django,现在我正在创建我的第一个应用,我按照教程中的每一步(https://docs.djangoproject.com/en/1.9/intro/tutorial01/),但它不起作用,它让我失望执行python manage.py runserver时出现以下错误行:

Unhandled exception in thread started by <function wrapper at 0x7ffdfa76d8c0>

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in          wrapper
    fn(*args, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver         .py", line 116, in inner_run
    self.check(display_num_errors=True)

  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426         , in check

    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75,          in run_checks
    new_errors = check(app_configs=app_configs)

  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 10, in          check_url_config
    return check_resolver(resolver)

  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 19, in          check_resolver
    for pattern in resolver.url_patterns:

  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in          __get__
    res = instance.__dict__[self.name] = self.func(instance)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, i         n url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in          __get__
    res = instance.__dict__[self.name] = self.func(instance)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, i         n 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/boss/Descargas/Python-2.7.5/mysite/testsite/testsite/urls.py", line 21, in          <module>
    url(r'^polls/', include('polls.urls')),

NameError: name 'include' is not defined

1 个答案:

答案 0 :(得分:5)

您忘记在mysite/urls.py中导入包含。

from django.conf.urls import include, url