I'm trying to use django-advanced-filters.
Python 3.8.10
Django==3.2
django-advanced-filters==2.0.0
sqlparse==0.4.3
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'advanced_filters',
'semantics',
'sites',
]
Urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^advanced_filters/', include('advanced_filters.urls')),
]
Admin
class SemanticsClusterAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
raw_id_fields = ("page",)
list_display = ["id", "detail_view", "page", "name", ]
advanced_filter_fields = (
'id',
'page',
)
exclude = []
admin.site.register(SemanticsClusters, SemanticsClusterAdmin)
Traceback
$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 75, in handle
self.check(databases=[database])
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
all_issues = checks.run_checks(
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/michael/Documents/PyCharmProjects/marketing3/marketing3/marketing3/urls.py", line 22, in <module>
url(r'^advanced_filters/', include('advanced_filters.urls')),
File "/home/michael/Documents/PyCharmProjects/marketing3/venv/lib/python3.8/site-packages/django/template/defaulttags.py", line 1369, in url
bits = token.split_contents()
AttributeError: 'tuple' object has no attribute 'split_contents'
Documentation: https://github.com/modlinltd/django-advanced-filters/blob/develop/README.rst
Could you help me understand why it blows up? And how to cope with the problem?
CodePudding user response:
After studying the documentation for Django and the Readme for Django Advance Filters. It looks like there is a typo or deprecated use of "url" in the Readme for Advance Filters
Instead of
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^advanced_filters/', include('advanced_filters.urls')),
]
Use:
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^advanced_filters/', include('advanced_filters.urls')),
]