运行简单的django应用程序时出错

时间:2017-04-24 05:10:35

标签: python django

knysys@kshahidLT ~/Desktop/firsrproject $ python manage.py runserver


Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7fbcdea6e050>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-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/knysys/Desktop/firsrproject/firsrproject/urls.py", line 22, in <module>
    url(r'^', include('marcador.urls')),
  File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/knysys/Desktop/firsrproject/marcador/urls.py", line 6, in <module>
    name='marcador_bookmark_user'),
  File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 85, in url
    raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().

1 个答案:

答案 0 :(得分:0)

从错误日志中,urlpatterns似乎包含urls.py中第22行的字符串。

django 1.10中,您无法将导入路径传递给url(),需要传递视图功能。

将此url(r'^', include('marcador.urls'))更改为url(r'^posts/$', postSuccess),您需要导入from marcador.views import postSuccess

假设你的marcador.views.py:

from django.shortcuts import render
from django.http import HttpResponse

def postSuccess(request):
    response = "<h1>Success</h1>"
    return HttpResponse(response)