django-rest-framework-bulk
django-rest-framework-bulk copied to clipboard
TypeError: as_view() takes 1 positional argument but 2 were given
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x102470840>
Traceback (most recent call last):
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/django/urls/resolvers.py", line 303, 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 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/src/server/veundmint/veundmint/urls.py", line 33, in <module>
url(r'^', include(router.urls)),
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/rest_framework/routers.py", line 81, in urls
self._urls = self.get_urls()
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/rest_framework/routers.py", line 355, in get_urls
urls = super(DefaultRouter, self).get_urls()
File "/Users/n/Sites/VEUNDMINT_TUB_Brueckenkurs/venv/lib/python3.5/site-packages/rest_framework/routers.py", line 261, in get_urls
view = viewset.as_view(mapping, **route.initkwargs)
TypeError: as_view() takes 1 positional argument but 2 were given
My code is exactly like in the example in the README
# Routers provide an easy way of automatically determining the URL conf.
router = BulkRouter()
router.register(r'server-action', WebsiteActionViewSet)
router.register(r'score', ScoreViewSet, base_name='scores')
router.register(r'whoami', UserViewSet, base_name='whoami')
router.register(r'foo', FooViewSet)
urlpatterns = [
#url(r'^', include('veundmint_base.urls')),
url(r'^', include(router.urls)),
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api-token-auth/', obtain_jwt_token),
]
when I do
router.register(r'foo', FooViewSet.as_view(), base_name='foo')
The API endpoint foo/
is not available
It would be great to have a simple_app that also works in django 1.8 or restframework > 3
Just ran into this as well. Tested on 0.2.1 and on the latest master.
Ugh, this is due to poor explanation in the README. The example given there uses a View, not a ViewSet, which I failed to notice due to the name being really long. Switching to having my ViewSet inherit from BulkModelViewSet fixed the issue.
@melinath with all the problems I see you're finding and fixing, I don't suppose you have a fork of this repo before I start getting in to it?
@someidiot I've been fine with workarounds for now; I usually prefer not to fork unless absolutely necessary.
apologies for delays everyone. doing house renovations.... so no time to look at any of my open-source stuff. I promise eventually I will actually take a look at the issues in this repo. they have been piling up....
@miki725 thanks for making this!
Agree with @melinath, thanks for making this. As long as issues are properly identified and solvable...
You shouldn't be including the as_view()
when you register a view into the router.
router.register(r'foo', FooViewSet.as_view(), base_name='foo'
This should look like
router.register(r'foo', FooViewSet, base_name='foo'
You shouldn't be including the
as_view()
when you register a view into the router.router.register(r'foo', FooViewSet.as_view(), base_name='foo'
This should look like
router.register(r'foo', FooViewSet, base_name='foo'
in which file should include this
You shouldn't be including the
as_view()
when you register a view into the router.router.register(r'foo', FooViewSet.as_view(), base_name='foo'
This should look like
router.register(r'foo', FooViewSet, base_name='foo'
in which file should include this
urls.py