'tuple' object has no attribute 'split_contents' - django

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?

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')),
]

Related

How to fix 'Specifying a namespace in include() without providing an app_name '

I am facing with the problem of setting the app_name attribute in the included module.
Despite the fact that I have seen similar answers on how to fix it, I did not find something working for me.
Here is my urls.py
from django.conf.urls import url,include
from django.contrib import admin
from intranet import views,forms
from django.contrib.auth import views as auth_views
from django.conf import settings
from rest_framework import routers
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import reverse
router = routers.DefaultRouter()
router.register(r'pharmakeia', views.PharmakeiaViewSet,base_name='pharmakeia')
router.register(r'doctors', views.DoctorsViewSet,base_name='doctors')
router.register(r'new-pharmakeia', views.VriskoViewSet,base_name='new-pharmakeia')
router.register(r'new-all-pharmakeia', views.VriskoAllViewSet,base_name='new-all-pharmakeia')
views.json_data,base_name='test_pharmakeia')
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^rest/', include(router.urls, namespace='rest')),
url(r'^api-auth/', include(rest_framework.urls, namespace='rest_framework')),
Then I changed the script:
I tried to declare an app_name variable
app_name="intranet"
and then I tried to fix the urls containing the include function
url(r'^rest/', include((router.urls,app_name), namespace='rest')),
url(r'^api-auth/', include(('rest_framework.urls',app_name), namespace='rest_framework')),
I face a new problem
"ModuleNotFoundError: No module named 'router' despite the fact that I have already defined rooter**
Here is my output from command line
self._target(*self._args, **self._kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/www/wwwroot/geolocator/geolocator/urls.py", line 40, in <module>
url(r'^rest/', include(router.urls, namespace='rest')),
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
^C(geolocator_venv) [root#76 geolocator]# clear
(geolocator_venv) [root#76 geolocator]# python manage.py runserver 76.neurosynthesis.com:19999
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/root/.pyenv/versions/3.7.2/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/root/.pyenv/versions/3.7.2/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/www/wwwroot/geolocator/geolocator/urls.py", line 40, in <module>
url(r'^rest/', include(router.urls, namespace='rest')),
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
Any idea how to fix this?

Using ArrayField and adding 'django_postgres_extensions' to INSTALLED_APPS causes LookupError: No installed app with label 'admin'

I am using postgres with Django and one of the fields in the model should be an Array. When I was trying to use it I was recommended that I use "django_postgres_extensions" so I ran "pip install django_postgres_extensions" and even added 'django_postgres_extensions' to INSTALLED_APPS to settings.py.
from django_postgres_extensions.models.fields import ArrayField
from django.conf import settings
from django.db import models
class Wanted(models.Model):
firstName = models.CharField(max_length=255, null=False, blank=False, default="default")
lastName = models.CharField(max_length=255, null=False, blank=False, default="default")
encodings = ArrayField(models.IntegerField(), default=[], form_size=10, blank=True)
photo = models.ImageField(upload_to="wanted/", null=True, blank=True)
Each time I run "python manage.py runserver", I get the following error:
Watching for file changes with StatReloader
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\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 "C:\Users\Kyoko\Desktop\KYOKO\Work\Talan\GitProject\IBCS\server\src\models\models.py", line 80, in <module>
class Wanted(models.Model):
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 156, in __new__
new_class.add_to_class(obj_name, obj)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 733, in contribute_to_class
self.set_attributes_from_name(name)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\postgres\fields\array.py", line 76, in set_attributes_from_name
self.base_field.set_attributes_from_name(name)
TypeError: set_attributes_from_name() missing 1 required positional argument: 'name'
Traceback (most recent call last):
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'admin'
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 "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 272, in run
get_resolver().urlconf_module
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\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 "C:\Users\Kyoko\Desktop\KYOKO\Work\Talan\GitProject\IBCS\server\src\IBCS\urls.py", line 7, in <module>
path('admin/', admin.site.urls),
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py", line 256, in inner
self._setup()
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\admin\sites.py", line 529, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "C:\Users\Kyoko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 162, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'admin'.
Edit: INSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'django_postgres_extensions',
'rest_framework',
'corsheaders',
'models',
'identity',
'agents',
'admincp',
]

ImportError: cannot import name 'URLPattern'

I am using django 1.11 and django rest version 3.
and i used drf-nested routers . for makin path like /abc/{id}/xyz/where abc and xyz are two views from AbcViewSet and XyzViewSet.
urls.py
from rest_framework_nested import routers
router = routers.SimpleRouter()
router.register(r'abc',AbcViewset)
abc_router = routers.NestedSimpleRouter(router,r'abc', lookup='abc')
abc_router.register(r'xyz', XyzViewset, base_name='abc-xyz')
urlpatterns = [
url(r'', include(router.urls)),
]
And I got the following traceback. I dont know what is happening with the code and what the error exactly is?
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fb79f505a60>
Traceback (most recent call last):
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/home//.local/lib/python3.6/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/johan/.local/lib/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/home/johan/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/johan/.local/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/johan/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/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 "/home/johan/Documents/Abc/backend/abc/urls.py", line 24, in <module>
from rest_framework.documentation import include_docs_urls
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/documentation.py", line 6, in <module>
from rest_framework.schemas import SchemaGenerator, get_schema_view
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/schemas/__init__.py", line 25, in <module>
from .generators import SchemaGenerator
File "/home/johan/.local/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 18, in <module>
from rest_framework.compat import (
ImportError: cannot import name 'URLPattern'
How can this error be resolved?

NameError: account not defined

I'm trying to create a simple registration form using django1.11.5
I created a project called mysite using the command:
django-admin.py startproject mysite .
And I have created an app called account using the code:
python manage.py startapp account
In the urls.py file of the folder mysite I specified the urlto be accessed as follows:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^account/',include(account.urls)),
url(r'^admin/', admin.site.urls),
]
However when I'm trying to migrate or runserver I'm getting the following error.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000273BFBDFC80>
Traceback (most recent call last):
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Welcome\django\myvenv\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Welcome\django\mysite\urls.py", line 19, in <module>
url(r'^account/',include(account.urls)),
NameError: name 'account' is not defined
So can someone please help. I'm new at this
When you 'include' urls, the reference to the app containing the urls should be a string like so:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
...
url(r'^account/', include('account.urls')),
...
]
You are trying to import the actual app, but that is not necessary in this case.
Does that make sense?

error running server Django syntax error

I'm trying to get through a Django tutorial and I'm running into a syntax error when I try to run manage.py runserver. The error is below.
(C:\Users\Scott\Anaconda3) C:\Users\Scott\Desktop\django
tutorials\mysite>manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function
check_errors.<locals>.wrapper at 0x000001705F6D48C8>
Traceback (most recent call last):
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Scott\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Scott\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Scott\Desktop\django tutorials\mysite\mysite\urls.py", line 22
]
^
SyntaxError: invalid syntax
mysite\urls.py is below. I'm not sure what is wrong with the syntax, or why it's pointing to the bracket.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')]
Please use a list type for urlpatterns.
Leave a comma at the end of the list:
urlpatterns = [
url(r'^$', views.index, name='index'),
]