django

解决python - AttributeError: 'RegexURLPattern' object has no attribute '_callback'

分享于

推荐:AttributeError: 'NoneType' object has no attribute

python 读取excel文件报错:  basetable = data.sheet_by_index(0) AttributeError: 'NoneType' object has no attribute 'sheet_by_index' def open_excel(file

2018阿里云全部产品优惠券(好东东,强烈推荐)
领取地址https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=gh9qh5ki&utm_source=gh9qh5ki

 

I'm newbie in python. I used this tutorial http://www.django-rest-framework.org/tutorial/quickstart/, but have an issue with RegexURLPattern. Full stack trace of issue:

 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'

My urls.py content:

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'))
]

What i'am doing wrong? Help please...

python django django-rest-framework 
 | 
  this question
 edited Jan 5 '16 at 16:24 asked Jan 5 '16 at 12:03 NilsHolgerson 174 11 1   Please show the full traceback. Which Django and DRF version are you using? –  knbk Jan 5 '16 at 13:32      updated stack trace... –  NilsHolgerson Jan 5 '16 at 16:24 1   Django version - 1.10 DRF - i don't know. I installed it with pip install djangorestframework –  NilsHolgerson Jan 5 '16 at 16:33

 | 

Answers
4

解决方法

You are using the development version of Django. DRF is not yet compatible. You should install Django 1.8.x or 1.9.x instead.


 | 
  this answer
 answered Jan 5 '16 at 16:35 knbk 24.2k 3 30 54 3   Just for reference: Django 1.10 is supported as of RestFramework 3.4.0. –  Amir Ali Akbari Sep 21 '16 at 6:54


 | 

It looks like you project layout differs from the quickstart.

from quickstart import views

should be:

 

推荐:AttributeError 'module' object has no attribute 'handlers'--Python子模块导入问题

想使用python的logging模块记录日志, 并使用RotatingFileHandler来处理日志以便于在日志文件超过指定的大小后会重新生成新的日志文件。 基本代码如下: import

 

from tutorial.quickstart import views

 | 
  this answer
 answered Jan 5 '16 at 12:41 Linovia 4,697 1 4 16      If I edit this line like you say, i've another error: ImportError: No module named 'tutorial.quickstart' –  NilsHolgerson Jan 5 '16 at 12:48      As I said, your quick start layout differs from the documentation. –  Linovia Jan 5 '16 at 12:53      Please make sure you were in the tutorial directory when creating the quick start application. –  Linovia Jan 5 '16 at 12:54      /Users/user/tutorial/tutorial/quickstart –  NilsHolgersonJan 5 '16 at 12:56


 | 

In my case, It seems that DRF was not installed. I ran pip install djangorestframeworkand my 'runserver' command worked just fine.


 | 
  this answer
 answered Oct 13 '16 at 17:30 jignesh 50 9


 | 

I have the same problem on Django 1.10 and 1.11. Solution: update djangorestframework to the latest version

pip install -U djangorestframework

 | 
  this answer
 answered Apr 11 at 11:39 Volodymyr Pavlenko 1


 | 

 

推荐:AttributeError: 'classmethod' object has no attribute '__module__'

AttributeError: 'classmethod' object has no attribute '__module__'  Luo Weifeng 2011-7-27 语言:python 今天被一个奇怪的错误一直纠缠着前进不了, 是关于

posted @ 2018-04-03 00:04  xiaojikuaipao  阅读(321)  评论(0编辑  收藏  举报