Django, upgrading to 1.9
Question: I evolve my Django version to 1.9 (before I had the 1.6 or 1.7), so I modify
many obseltes things...

But I have a problem with theses lines in my urls.py :

    
    
    import django
    import main_app 
    from django.conf.urls import patterns, include, url
    from django.views.generic import TemplateView, ListView
    from django.contrib import admin
    from django.conf import settings
    from django.conf.urls.static import static
    from main_app.views import *
    from main_app.views import password_reset_confirm
    ... # many urls
    url(r'^authentification/$', django.contrib.auth.views.login),
    url(r'^forget/send/$', django.contrib.auth.views.password_reset_done),
    url(r'^password/$', django.contrib.auth.views.password_reset),
    url(r'^password_forget/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', main_app.views.password_reset_confirm),
    url(r'^password-init/$', django.contrib.auth.views.password_reset_complete),
    

I have this error when I write "python manage.py runserver" :

    
    
    Unhandled exception in thread started by <function wrapper at 0x7f5bcf01af50>
    Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check(display_num_errors=True)
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
    File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
    File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 10, in check_url_config
    return check_resolver(resolver)
    File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 19, in check_resolver
    for pattern in resolver.url_patterns:
    File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
    File "/usr/lib/python2.7/importlib/__init__.py", line 37, in  import_module
    __import__(name)
    File "/home/yb/web/carzuip/carzuip/urls.py", line 55, in <module>
    url(r'^authentification/$', django.contrib.auth.views.login),
    NameError: name 'django' is not defined
    

I don't understand why I have a problem just with those 5 urls ??!

Thank's


Answer: That code _doesn't_ show you importing `django`: it shows you importing
elements underneath it, but never the name itself. It is a fundamental
principle of Python that you must import or define every name you use. In your
case, `import django` at the top would work, although note you would then have
another problem when the code gets to the password_reset URL since that is
referenced from `main_app` which you again haven't imported.

