2016-01-05 17 views
5

Ich bin ein Neuling in Python. Ich habe dieses Tutorial verwendet http://www.django-rest-framework.org/tutorial/quickstart/, aber habe ein Problem mit RegexURLPattern. Voll Stack-Trace der Ausgabe:AttributeError: 'RegexURLPattern' Objekt hat kein Attribut '_callback'

Unhandled exception in thread started by <function check_errors. 
<locals>.wrapper at 0x103c8cf28> 
Traceback (most recent call last): 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/utils/autoreload.py", line 226, in wrapper 
fn(*args, **kwargs) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/management/commands/runserver.py", line 116, in inner_run 
self.check(display_num_errors=True) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/management/base.py", line 366, in check 
include_deployment_checks=include_deployment_checks, 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/checks/registry.py", line 75, in run_checks 
new_errors = check(app_configs=app_configs) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/checks/urls.py", line 10, in check_url_config 
return check_resolver(resolver) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/checks/urls.py", line 19, in check_resolver 
for pattern in resolver.url_patterns: 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/utils/functional.py", line 35, in __get__ 
res = instance.__dict__[self.name] = self.func(instance) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/urlresolvers.py", line 379, in url_patterns 
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/utils/functional.py", line 35, in __get__ 
res = instance.__dict__[self.name] = self.func(instance) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Django-1.10.dev20151224130822-py3.5.egg/django/core/urlresolvers.py", line 372, in urlconf_module 
return import_module(self.urlconf_name) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/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 662, in exec_module 
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
File "/Users/igor/tutorial/tutorial/tutorial/urls.py", line 28, in <module> 
url(r'^', include(router.urls)), 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/rest_framework/routers.py", line 79, in urls 
self._urls = self.get_urls() 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/rest_framework/routers.py", line 321, in get_urls 
urls = format_suffix_patterns(urls) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/rest_framework/urlpatterns.py", line 64, in format_suffix_patterns 
return apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required) 
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/rest_framework/urlpatterns.py", line 27, in apply_suffix_patterns 
view = urlpattern._callback or urlpattern._callback_str 
AttributeError: 'RegexURLPattern' object has no attribute '_callback' 

Mein urls.py Inhalt:

from django.conf.urls import url, include 
from rest_framework import routers 
from quickstart import views 

router = routers.DefaultRouter() 
router.register(r'users', views.UserViewSet) 
router.register(r'groups', views.GroupViewSet) 

urlpatterns = [ 
     url(r'^', include(router.urls)), 
     url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) 
] 

Was i'am falsch? Hilfe bitte ...

+1

Bitte zeigen Sie die vollständige Traceback. Welche Django und DRF Version verwendest du? – knbk

+0

aktualisiert Stack-Trace ... – NilsHolgerson

+1

Django Version - 1.10 DRF - ich weiß es nicht. Ich habe es installiert mit ** pip install djangorestframework ** – NilsHolgerson

Antwort

13

Sie die Entwicklerversion von Django. DRF ist noch nicht kompatibel. Sie sollten stattdessen Django 1.8.x oder 1.9.x installieren.

+3

Nur als Referenz: Django 1.10 wird ab RestFramework 3.4.0 unterstützt. –

0

Es sieht wie Ihr Projekt Layout unterscheidet sich von der quickstart.

from quickstart import views 

sollte sein:

from tutorial.quickstart import views 
+0

Wenn ich diese Zeile bearbeiten, wie Sie sagen, habe ich einen anderen Fehler: ImportError: Kein Modul mit dem Namen 'tutorial.quickstart' – NilsHolgerson

+0

Wie gesagt, Ihr Schnellstart-Layout unterscheidet sich von der Dokumentation . – Linovia

+0

Bitte stellen Sie sicher, dass Sie beim Erstellen der Schnellstartanwendung im Tutorial-Verzeichnis waren. – Linovia

0

In meinem Fall scheint es, dass DRF nicht installiert war. Ich lief pip installieren djangorestframework und mein 'runserver' Befehl funktionierte gut.

2

Ich habe das gleiche Problem auf Django 1.10 und 1.11. Lösung: Update djangorestframework auf die neueste Version

pip install -U djangorestframework 
1

dieses verrückte Bugs ist. Ich verschwendete zwei Tagen mein Wochenende, es zu erkennen, müssen bestimmte Versionen installieren werden:

  • Django 1,11 (Meine letzte Version des 1.11.3)
  • djangorestframework 3.7
  • Python 3.6.5

Viel Glück, Leute!

Verwandte Themen