Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: as_view() takes 1 positional argument but 2 were given #55

Open
kaelteschutz opened this issue Oct 5, 2016 · 10 comments
Open

Comments

@kaelteschutz
Copy link

kaelteschutz commented Oct 5, 2016

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

@melinath
Copy link

Just ran into this as well. Tested on 0.2.1 and on the latest master.

@melinath
Copy link

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.

@someidiot
Copy link

@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?

@melinath
Copy link

melinath commented Nov 8, 2016

@someidiot I've been fine with workarounds for now; I usually prefer not to fork unless absolutely necessary.

@miki725
Copy link
Owner

miki725 commented Nov 8, 2016

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....

@melinath
Copy link

melinath commented Nov 8, 2016

@miki725 thanks for making this!

@velis74
Copy link

velis74 commented Dec 22, 2016

Agree with @melinath, thanks for making this. As long as issues are properly identified and solvable...

@kevin-brown
Copy link
Contributor

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'

@Dete-Desai
Copy link

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

@pythonista05
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants