Did you try adding the project to the name?  

'DEFAULT_PAGINATION_CLASS': 'app.api.pagination.PrimaryKeySortedPagination'

Here's the example in the 
docs: 
http://www.django-rest-framework.org/api-guide/pagination/#using-your-custom-pagination-class

On Tuesday, September 25, 2018 at 1:34:37 PM UTC-4, Chloe wrote:
>
> Hi there! I'm using a custom DEFAULT_PAGINATION_CLASS.
>
> It all loads, unit tests, and runs properly with the class's pagination, 
> but when I try to run python manage.py migrate, I get an error from DRF's 
> code trying to load DEFAULT_PAGINATION_CLASS. It complains AttributeError: 
> module 'api.pagination' has no attribute 'PrimaryKeySortedPagination'.
>
> I've tried:
>
>    - moving the pagination file into my core app alongside settings.py
>    - putting my 'api' app above 'rest_framework' in INSTALLED_APPS
>    - adding 'from pagination import PrimaryKeySortedPagination' to api's 
>    __init__.py
>    - and a few other things.
>
> Any help's appreciated! Thanks!
>
> In my settings.py:
>
> REST_FRAMEWORK = {
>
>     ....
>
>     ....
>
>     ....
>
>     'DEFAULT_PAGINATION_CLASS': 
> 'api.pagination.PrimaryKeySortedPagination',
>
>     'PAGE_SIZE': 100,
> }
>
>
> LOG:
>
> Traceback (most recent call last):
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 184, in import_from_string
>     return getattr(module, class_name)
> AttributeError: module 'api.pagination' has no attribute 
> 'PrimaryKeySortedPagination'
>
>
> During handling of the above exception, another exception occurred:
>
>
> Traceback (most recent call last):
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 183, in import_from_string
>     module = import_module(module_path)
>   File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126
> , in import_module
>     return _bootstrap._gcd_import(name[level:], package, level)
>   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
>   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
>   File "<frozen importlib._bootstrap>", line 955, in 
> _find_and_load_unlocked
>   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
>   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
>   File "<frozen importlib._bootstrap>", line 219, in 
> _call_with_frames_removed
>   File "/app/api/pagination.py", line 4, in <module>
>     from rest_framework import permissions, status, viewsets, mixins, 
> pagination
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/viewsets.py"
> , line 27, in <module>
>     from rest_framework import generics, mixins, views
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/generics.py"
> , line 26, in <module>
>     class GenericAPIView(views.APIView):
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/generics.py"
> , line 48, in GenericAPIView
>     pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 227, in __getattr__
>     val = perform_import(val, attr)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 170, in perform_import
>     return import_from_string(val, setting_name)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 187, in import_from_string
>     raise ImportError(msg)
> ImportError: Could not import 'api.pagination.PrimaryKeySortedPagination' 
> for API setting 'DEFAULT_PAGINATION_CLASS'. AttributeError: module 
> 'api.pagination' has no attribute 'PrimaryKeySortedPagination'.
>
>
> During handling of the above exception, another exception occurred:
>
>
> Traceback (most recent call last):
>   File "manage.py", line 15, in <module>
>     execute_from_command_line(sys.argv)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py"
> , line 381, in execute_from_command_line
>     utility.execute()
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py"
> , line 375, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py"
> , line 316, in run_from_argv
>     self.execute(*args, **cmd_options)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py"
> , line 350, in execute
>     self.check()
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py"
> , line 379, in check
>     include_deployment_checks=include_deployment_checks,
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py"
> , line 60, in _run_checks
>     issues.extend(super()._run_checks(**kwargs))
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py"
> , line 366, in _run_checks
>     return checks.run_checks(**kwargs)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py"
> , line 71, in run_checks
>     new_errors = check(app_configs=app_configs)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/checks.py"
> , line 9, in pagination_system_check
>     if api_settings.PAGE_SIZE and not api_settings.
> DEFAULT_PAGINATION_CLASS:
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 227, in __getattr__
>     val = perform_import(val, attr)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 170, in perform_import
>     return import_from_string(val, setting_name)
>   File 
> "/app/.heroku/python/lib/python3.6/site-packages/rest_framework/settings.py"
> , line 187, in import_from_string
>     raise ImportError(msg)
> ImportError: Could not import 'api.pagination.PrimaryKeySortedPagination' 
> for API setting 'DEFAULT_PAGINATION_CLASS'. ImportError: Could not import 
> 'api.pagination.PrimaryKeySortedPagination' for API setting 'DEFA
> ULT_PAGINATION_CLASS'. AttributeError: module 'api.pagination' has no 
> attribute 'PrimaryKeySortedPagination'..
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to