Django FormView:/ s3direct上的ViewDoesNotExist /

时间:2016-04-10 16:17:10

标签: python django

我在处理具有FormView的视图时遇到问题。我正在尝试使用s3direct插件。

错误指定'<app.views.MyView object at 0x7f7dd9222250>' is not a callable or a dot-notation path

我的观点

class MyView(FormView):
     template_name = 'form.html'
     form_class = S3DirectUploadForm

Forms.py

class S3DirectUploadForm(forms.Form):
    images = forms.URLField(widget=S3DirectWidget(
        dest='destination_key_from_settings',
        html=(
            '<div class="s3direct" data-policy-url="{policy_url}">'
            '  <a class="file-link" target="_blank" href="{file_url}">{file_name}</a>'
            '  <a class="file-remove" href="#remove">Remove</a>'
            '  <input class="file-url" type="hidden" value="{file_url}" id="{element_id}" name="{name}" />'
            '  <input class="file-dest" type="hidden" value="{dest}">'
            '  <input class="file-input" type="file" />'
            '  <div class="progress progress-striped active">'
            '    <div class="bar"></div>'
            '  </div>'
            '</div>'
        )))

urls.py

    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^s3direct/', views.MyView()),

]

文件追溯

Internal Server Error: /s3direct/
Traceback (most recent call last):
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 134, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 376, in resolve
    sub_match = pattern.resolve(new_path)
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 248, in resolve
    return ResolverMatch(self.callback, args, kwargs, self.name)
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 255, in callback
    self._callback = get_callable(self._callback_str)
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
    result = user_function(*args, **kwds)
  File "/home/amogh/cartoon_mango/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 102, in get_callable
    "'%s' is not a callable or a dot-notation path" % lookup_view
ViewDoesNotExist: '<app.views.MyView object at 0x7f479a5502d0>' is not a callable or a dot-notation path
[10/Apr/2016 16:14:14] "GET /s3direct/ HTTP/1.1" 500 81123dragondisk (1.0.5-0) 

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

在网址中使用基于类的视图时,您应该调用.as_view()方法。

替换它:

url(r'^s3direct/', views.MyView()),

有了这个:

url(r'^s3direct/', views.MyView.as_view()),