# AttributeError: 'function' object has no attribute 'as\_view'

**URL:** <https://forum.djangoproject.com/t/attributeerror-function-object-has-no-attribute-as-view/24704>\
**Category:** Mystery Errors\
**Created:** [October 22, 2023, 4:24am UTC](https://forum.djangoproject.com/t/attributeerror-function-object-has-no-attribute-as-view/24704 "2023-10-22T04:24:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Supremebosslife](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/supremebosslife/32/16567_2.png) [@Supremebosslife](https://forum.djangoproject.com/u/Supremebosslife)\
**Post date:** [October 22, 2023, 4:24am UTC](https://forum.djangoproject.com/t/attributeerror-function-object-has-no-attribute-as-view/24704/1 "2023-10-22T04:24:28Z")

</div>

I am trying to create a class-based view for SellerOrderListView.

in seller\_views.py i defined the view as

```auto
class SellerOrderListView(ListView):
    model = SellerOrder # Use the SellerOrder model
    template_name = 'seller/seller_orders_list.html' # Create the template for the seller order list
    context_object_name = 'seller_orders'

```

in app urls.py, import statement is: `from AfriExportingapp.seller_views import SellerOrderListView`

url pattern is: `path('seller/orders/', SellerOrderListView.as_view(), name='seller_orders'),`

yet, i get this while running migrations:

```auto
 File "C:\Users\LENOVO E490\Apps\AfriExporting\manage.py", line 22, in <module>
    main()
  File "C:\Users\LENOVO E490\Apps\AfriExporting\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\management\ __init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\management\ __init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\management\base.py", line 453, in execute
    self.check()
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\management\base.py", line 485, in check
    all_issues = checks.run_checks(
                 ^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
           ^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\urls\resolvers.py", line 494, in check
    for pattern in self.url_patterns:
                   ^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance. __dict__ [self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
                       ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\utils\functional.py", line 57, in __get__
    res = instance. __dict__ [self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64 __qbz5n2kfra8p0\Lib\importlib\__ init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\LENOVO E490\Apps\AfriExporting\AfriExporting\urls.py", line 24, in <module>
    path('', include('AfriExportingapp.urls')),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LENOVO E490\Apps\AfriExporting\venv\Lib\site-packages\django\urls\conf.py", line 38, in include
    urlconf_module = import_module(urlconf_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64 __qbz5n2kfra8p0\Lib\importlib\__ init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\LENOVO E490\Apps\AfriExporting\AfriExportingapp\urls.py", line 42, in <module>
    path('seller/orders/', SellerOrderListView.as_view(), name='seller_orders'),
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'as_view'

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 22, 2023, 2:30pm UTC](https://forum.djangoproject.com/t/attributeerror-function-object-has-no-attribute-as-view/24704/2 "2023-10-22T14:30:29Z")

</div>

When posting code or error messages here, please surround the code (or error message) between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. (I’ve taken the liberty of updating your original post.) Single line code fragments can be surrounded by single backtick characters.

Please post your complete `seller_views.py` file. Either something isn’t quite as you have described here, or there’s something else in that file causing problems.

---

<div class="post-metadata">

**Author:** ![csAfter40](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/csafter40/32/15749_2.png) [@csAfter40](https://forum.djangoproject.com/u/csAfter40)\
**Post date:** [October 22, 2023, 10:24pm UTC](https://forum.djangoproject.com/t/attributeerror-function-object-has-no-attribute-as-view/24704/3 "2023-10-22T22:24:24Z")

</div>

Hi [Supremebosslife](https://forum.djangoproject.com/u/Supremebosslife),  
Based on the error message you received, it seems your SellerOrderListView class is being treated as a function. I can think of 3 possible reasons:

1. Check if you have applied a decorator to your SellerOrderListView class in `seller_views.py` which isn’t visible in the code you provided. Some decorators like @login\_required are meant to be used for function based views and returns a function.

```auto
@login_required
class SellerOrderListView(ListView):
    model = SellerOrder # Use the SellerOrder model
    template_name = 'seller/seller_orders_list.html' # Create the template for the seller order list
    context_object_name = 'seller_orders'

```

1. You may have accidentally created a function with name “ListView” somewhere in your seller\_views.py

```auto
def ListView():
    #function based view code

```

1. Check your ListView import.It should be

```auto
from django.views.generic.list import ListView

```
