I recently started development on Django 1.9 for python. I am a newbie in python as well. Just working through examples and codes to learn stuff. I came across include in django.conf.urls which when I used caused errors. I couldn't understand why was that? Because I have used it at other places which don't cause errors.
from django.conf.urls import url, include
from accounts import views as acc_views
urlpatterns = [
url(r'^home$', acc_views.home, name='accounts_home'),
]
Below is when this gives error.
urlpatterns = [
url(r'^home$', include(acc_views.home), name='accounts_home'),
]
Here is the exception:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x035424F8>
Traceback (most recent call last):
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\urlresolvers.py", line 419, in url_patterns
iter(patterns)
TypeError: 'function' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\checks\urls.py", line 27, in check_resolver
warnings.extend(check_resolver(pattern))
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\checks\urls.py", line 27, in check_resolver
warnings.extend(check_resolver(pattern))
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python35-32\VirtualENV\socialnetwork296\lib\site-packages\django\core\urlresolvers.py", line 426, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<function home at 0x03D45A50>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
What is include actually doing?