import from views.py does not work from app
Question: I'm working with django and I'm trying to get a simple app functional.

The app is supposed to deliver a simple 'Hello world'-view but my_app/urls.py
fails to import methods from my_app/views.py.

my app is named SocialUrl

Here is my-project/urls.py.

    
    
    from django.conf.urls import patterns, include, url
    # from SocialUrl.views import test
    
    from django.contrib import admin
    admin.autodiscover()
    
        urlpatterns = patterns('',
        url(r'^admin/', include(admin.site.urls)),
        url(r'^/su/', include('SocialUrl.urls')),
        # url(r'^$', test),
    )
    

Here is my-app/urls.py

    
    
    from django.conf.urls import patterns, url
    from . import views
    
    urlpatterns = patterns('',
        # ex: /polls/
        url(r'^test$', views.test()),
    )
    

Here is my-app/views.py

    
    
    from django.shortcuts import render
    from django.template import RequestContext
    
    def test(request):
        return render(request, 'test.html', RequestContext(request, {}))
    

Note that the testlines in my-project/urls.py works correctly.

My folder structure looks like this: my-project my-project my-app

I've added this in my-project/settings.py

    
    
    TEMPLATE_DIRS = (
        os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
        os.path.join(BASE_DIR, 'SocialUrl', 'templates').replace('\\', '/'),
    )
    

I get the following error:

    
    
        Environment:
    
    
        Request Method: GET
        Request URL: http://127.0.0.1:8000/
    
        Django Version: 1.6.2
        Python Version: 2.7.6
        Installed Applications:
        ('django.contrib.admin',
         'django.contrib.auth',
         'django.contrib.contenttypes',
         'django.contrib.sessions',
         'django.contrib.messages',
         'django.contrib.staticfiles',
         'SocialUrl')
        Installed Middleware:
        ('django.contrib.sessions.middleware.SessionMiddleware',
         'django.middleware.common.CommonMiddleware',
         'django.middleware.csrf.CsrfViewMiddleware',
         'django.contrib.auth.middleware.AuthenticationMiddleware',
         'django.contrib.messages.middleware.MessageMiddleware',
         'django.middleware.clickjacking.XFrameOptionsMiddleware')
    
    
        Traceback:
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\core\handlers\base.py" in get_response
          101.                 resolver_match = resolver.resolve(request.path_info)
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\core\urlresolvers.py" in resolve
          318.             for pattern in self.url_patterns:
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\core\urlresolvers.py" in url_patterns
          346.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
          341.             self._urlconf_module = import_module(self.urlconf_name)
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\utils\importlib.py" in import_module
          40.         __import__(name)
        File "C:\Users\Sverker\Dropbox\Coomba\SbrgCoomba\SbrgCoomba\urls.py" in <module>
          13.     url(r'^/su/', include('SocialUrl.urls')),
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\conf\urls\__init__.py" in include
          26.         urlconf_module = import_module(urlconf_module)
        File "C:\Users\Sverker\.virtualenvs\coomba\lib\site-packages\django\utils\importlib.py" in import_module
          40.         __import__(name)
        File "C:\Users\Sverker\Dropbox\Coomba\SbrgCoomba\SocialUrl\urls.py" in <module>
          7.     url(r'^$', test),
    
        Exception Type: NameError at /
        Exception Value: name 'test' is not defined
    

I have tried various combinations of the 'from . import views'-line in my-
app/urls.py eg. 'from views import test'

Edit:

still disfunctional my-app/urls.py

    
    
    from django.conf.urls import patterns, url
    from views import test
    
    urlpatterns = patterns('',
        # ex: /polls/
        url(r'^$', test),
    )
    


Answer: The problem is that you really have this line in your app `urls.py`:

    
    
    url(r'^$', test)
    

The error says that `test` is not defined. Just define (import) it:

    
    
    from views import test
    

