Django import error in views - no module named 'x' - python

I keep getting an error that there's no such module.
The project name is gmblnew, and I have two subfolders- core and gmblnew - the app I'm working on is core.
My urls.py file is
from django.conf.urls import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'gmblnew.views.home', name='home'),
# url(r'^gmblnew/', include('gmblnew.foo.urls')),
url(r'^league/', include('core.views.league')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
This seems to be fine. The views.py file is:
from django.http import HttpResponse
def league(request):
from core.models import Division
response = HttpResponse()
response['mimetype'] = 'text/plain'
response.write("<HTML><>BODY>\n")
response.write("< TABLE BORDER=1><CAPTION>League List</CAPTION><TR>\n")
all_leagues = Division.objects.all()
for league in all_leagues:
response.write("<TR>\n")
response.write("<TD> %s" % league)
response.write("</TD>\n")
response.write("</BODY></HTML>")
return response
Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Users/chris/Dropbox/Django/gmblnew/gmblnew/urls.py" in <module>
12. url(r'^league/', include('core.views.league')),
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
25. urlconf_module = import_module(urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /admin/
Exception Value: No module named league
I've tried a number of variants on the url(r'^league/', include('core.views.league')), line, including gmblnew.core.views.league, views.league, views.view_league, etc. I'm obviously missing something super simple on the structure of that line.

Your problem is here:
url(r'^league/', include('core.views.league')),
By using include you are specifying a module, which does not exist.
include is used to include other url confs, and not to target view methods
What you want is refer to the view method league
url(r'^league/$', 'core.views.league'),
should work.
Also, note the $ after ^league/ , which represents the end of the URL pattern.

include takes a path to a url file, not a view. Just write this instead:
url(r'^league/', 'core.views.league'),

Related

Python Django | Importing views in urls.py [duplicate]

After upgrading to Django 1.10, I get the error:
TypeError: view must be a callable or a list/tuple in the case of include().
My urls.py is as follows:
from django.conf.urls import include, url
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
The full traceback is:
Traceback (most recent call last):
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 303, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/alasdair/dev/urlproject/urlproject/urls.py", line 28, in <module>
url(r'^$', 'myapp.views.home'),
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
Django 1.10 no longer allows you to specify views as a string (e.g. 'myapp.views.home') in your URL patterns.
The solution is to update your urls.py to include the view callable. This means that you have to import the view in your urls.py. If your URL patterns don't have names, then now is a good time to add one, because reversing with the dotted python path no longer works.
from django.conf.urls import include, url
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
If there are many views, then importing them individually can be inconvenient. An alternative is to import the views module from your app.
from django.conf.urls import include, url
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views
urlpatterns = [
url(r'^$', myapp_views.home, name='home'),
url(r'^contact/$', myapp_views.contact, name='contact'),
url(r'^login/$', auth_views.login, name='login'),
]
Note that we have used as myapp_views and as auth_views, which allows us to import the views.py from multiple apps without them clashing.
See the Django URL dispatcher docs for more information about urlpatterns.
This error just means that myapp.views.home is not something that can be called, like a function. It is a string in fact. While your solution works in django 1.9, nevertheless it throws a warning saying this will deprecate from version 1.10 onwards, which is exactly what has happened. The previous solution by #Alasdair imports the necessary view functions into the script through either
from myapp import views as myapp_views or
from myapp.views import home, contact
You may also get this error if you have a name clash of a view and a module. I've got the error when i distribute my view files under views folder, /views/view1.py, /views/view2.py and imported some model named table.py in view2.py which happened to be a name of a view in view1.py. So naming the view functions as v_table(request,id) helped.
Just in case you got the error on your terminal, it is possible that if you stop the server and then run it again, it would work.
On Windows:
ctrl+c
to stop the server
then run the server again:
python manage.py runserver
Cheers.
Your code is
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
change it to following as you're importing include() function :
urlpatterns = [
url(r'^$', views.home),
url(r'^contact/$', views.contact),
url(r'^login/$', views.login),
]
change
register = template.Library()
to
registerr = template.Library()
resovled my issue

Django - TypeError: view must be a callable or a list/tuple in the case of include() [duplicate]

After upgrading to Django 1.10, I get the error:
TypeError: view must be a callable or a list/tuple in the case of include().
My urls.py is as follows:
from django.conf.urls import include, url
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
The full traceback is:
Traceback (most recent call last):
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 303, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/alasdair/dev/urlproject/urlproject/urls.py", line 28, in <module>
url(r'^$', 'myapp.views.home'),
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
Django 1.10 no longer allows you to specify views as a string (e.g. 'myapp.views.home') in your URL patterns.
The solution is to update your urls.py to include the view callable. This means that you have to import the view in your urls.py. If your URL patterns don't have names, then now is a good time to add one, because reversing with the dotted python path no longer works.
from django.conf.urls import include, url
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
If there are many views, then importing them individually can be inconvenient. An alternative is to import the views module from your app.
from django.conf.urls import include, url
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views
urlpatterns = [
url(r'^$', myapp_views.home, name='home'),
url(r'^contact/$', myapp_views.contact, name='contact'),
url(r'^login/$', auth_views.login, name='login'),
]
Note that we have used as myapp_views and as auth_views, which allows us to import the views.py from multiple apps without them clashing.
See the Django URL dispatcher docs for more information about urlpatterns.
This error just means that myapp.views.home is not something that can be called, like a function. It is a string in fact. While your solution works in django 1.9, nevertheless it throws a warning saying this will deprecate from version 1.10 onwards, which is exactly what has happened. The previous solution by #Alasdair imports the necessary view functions into the script through either
from myapp import views as myapp_views or
from myapp.views import home, contact
You may also get this error if you have a name clash of a view and a module. I've got the error when i distribute my view files under views folder, /views/view1.py, /views/view2.py and imported some model named table.py in view2.py which happened to be a name of a view in view1.py. So naming the view functions as v_table(request,id) helped.
Just in case you got the error on your terminal, it is possible that if you stop the server and then run it again, it would work.
On Windows:
ctrl+c
to stop the server
then run the server again:
python manage.py runserver
Cheers.
Your code is
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
change it to following as you're importing include() function :
urlpatterns = [
url(r'^$', views.home),
url(r'^contact/$', views.contact),
url(r'^login/$', views.login),
]
change
register = template.Library()
to
registerr = template.Library()
resovled my issue

Adding a Second URL Pattern in Django Causes Attribute Error [duplicate]

I've been trying to learn Django for the past few days, but recently I've stumbled upon a problem I can't seem to fix. After finishing Django's own tutorial on writing your first app I decided to go through it again. Only now I would replace everything to fit the requirements of the original app I was building.
So, everything went well until I got to part 3. When I try to load http://localhost:8000/lru/ I get the following error message:
AttributeError at /lru/
'module' object has no attribute 'index'
Traceback:
Internal Server Error: /favicon.ico
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
response = middleware_method(request)
File "/Library/Python/2.7/site-packages/django/middleware/common.py", line 69, in process_request
if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 551, in is_valid_path
resolve(path, urlconf)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 440, in resolve
return get_resolver(urlconf).resolve(path)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 319, in resolve
for pattern in self.url_patterns:
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/oyvindhellenes/Desktop/Sommerjobb 2013/mysite/mysite/urls.py", line 10, in <module>
url(r'^lru/', include('lru.urls', namespace="lru")),
File "/Library/Python/2.7/site-packages/django/conf/urls/__init__.py", line 25, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/oyvindhellenes/Desktop/Sommerjobb 2013/mysite/lru/urls.py", line 6, in <module>
url(r'^$', views.index, name='index')
AttributeError: 'module' object has no attribute 'index'
My code:
views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
lru/urls.py
from django.conf.urls import patterns, url
from lru import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
mysite/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
url(r'^lru/', include('lru.urls', namespace="lru")),
)
My folder structure looks like this:
mysite/
lru
templates
polls
manage.py
mysite
lru/
templates
urls.py
admin.py
__init__.py
models.py
tests.py
views.py
It's strange because I've done everything exactly as I did in the "polls" example turtorial. Just replacing the names. When I comment out url(r'^lru/', include('lru.urls', namespace="lru")), in mysite/urls.py, then http://localhost:8000/polls/ works fine, but I just can't seem to get /lru to work.
This is really killing me so any form of help would be appreciative!
Edit: Added full traceback
Import the urls.py module into your view. like this;
from django.http import HttpResponse
from . import urls
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
Either do this :
from lru.views import *
urlpatterns = patterns(
'',
url(r'^$', index, name='index')
)
or
from lru import views
urlpatterns = patterns(
'',
url(r'^$', 'views.index', name='index')
)
I hope this helps.
The second argument of url() should be string, anway I would change the lru/urls.py to:
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^$', 'lru.views.index', name='lru-index')
)
Hope it helps!
I just found out that Sublime text was mixing .... and tabs to make indentation, depending, I guess, on the copy/paste source.
This is how Django URLs works:
The urls from mysite/mysite/urls includes mysite/polls/urls, which tells that there are polls created inside the mysite project;
The mysite/polls/urls file tells us that the url "polls/", whenever visited, should call the function index() from mysite/polls/views which is what it states when you type the line:
urlpatterns = [
path('', views.index, name = 'index'),
]
And a very important thing to remember is to save each edited file before you run the server, so that files get updated. You can also keep the server running and save the files.

TypeError: view must be a callable or a list/tuple in url of image Django [duplicate]

After upgrading to Django 1.10, I get the error:
TypeError: view must be a callable or a list/tuple in the case of include().
My urls.py is as follows:
from django.conf.urls import include, url
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
The full traceback is:
Traceback (most recent call last):
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/urls/resolvers.py", line 303, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/alasdair/dev/urlproject/urlproject/urls.py", line 28, in <module>
url(r'^$', 'myapp.views.home'),
File "/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
Django 1.10 no longer allows you to specify views as a string (e.g. 'myapp.views.home') in your URL patterns.
The solution is to update your urls.py to include the view callable. This means that you have to import the view in your urls.py. If your URL patterns don't have names, then now is a good time to add one, because reversing with the dotted python path no longer works.
from django.conf.urls import include, url
from django.contrib.auth.views import login
from myapp.views import home, contact
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
If there are many views, then importing them individually can be inconvenient. An alternative is to import the views module from your app.
from django.conf.urls import include, url
from django.contrib.auth import views as auth_views
from myapp import views as myapp_views
urlpatterns = [
url(r'^$', myapp_views.home, name='home'),
url(r'^contact/$', myapp_views.contact, name='contact'),
url(r'^login/$', auth_views.login, name='login'),
]
Note that we have used as myapp_views and as auth_views, which allows us to import the views.py from multiple apps without them clashing.
See the Django URL dispatcher docs for more information about urlpatterns.
This error just means that myapp.views.home is not something that can be called, like a function. It is a string in fact. While your solution works in django 1.9, nevertheless it throws a warning saying this will deprecate from version 1.10 onwards, which is exactly what has happened. The previous solution by #Alasdair imports the necessary view functions into the script through either
from myapp import views as myapp_views or
from myapp.views import home, contact
You may also get this error if you have a name clash of a view and a module. I've got the error when i distribute my view files under views folder, /views/view1.py, /views/view2.py and imported some model named table.py in view2.py which happened to be a name of a view in view1.py. So naming the view functions as v_table(request,id) helped.
Just in case you got the error on your terminal, it is possible that if you stop the server and then run it again, it would work.
On Windows:
ctrl+c
to stop the server
then run the server again:
python manage.py runserver
Cheers.
Your code is
urlpatterns = [
url(r'^$', 'myapp.views.home'),
url(r'^contact/$', 'myapp.views.contact'),
url(r'^login/$', 'django.contrib.auth.views.login'),
]
change it to following as you're importing include() function :
urlpatterns = [
url(r'^$', views.home),
url(r'^contact/$', views.contact),
url(r'^login/$', views.login),
]
change
register = template.Library()
to
registerr = template.Library()
resovled my issue

django getting a urls.py syntax error and I am not sure why

Here is the traceback...
Traceback:
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
119. resolver_match = resolver.resolve(request.path_info)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
366. for pattern in self.url_patterns:
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
402. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
396. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/jeff/Django/langalang/langalang/langalang/urls.py" in <module>
11. url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
33. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
Exception Type: SyntaxError at /forum/
Exception Value: invalid syntax (urls.py, line 86)
I am almost certain there is no error in my syntax. I think it is happening because of some namespacing issues, but I can't see where.
I have my base urls like this...
urlpatterns = patterns('',
# Examples:
url(r'^admin-011001/', include(admin.site.urls)),
url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),
url(r'^(?P<page_lang>\w+)/forum/', include('djangobb_forum.urls', namespace='djangobb')),
and then my forum urls like this....
urlpatterns = patterns('',
# Forum
url('^$', forum_views.index, name='index'),
url('^(?P<forum_id>\d+)/$', forum_views.show_forum, name='forum'),
url('^moderate/(?P<forum_id>\d+)/$', forum_views.moderate, name='moderate'),
url('^search/$', forum_views.search, name='search'),
url('^misc/$', forum_views.misc, name='misc'),
url(r'^messages/', include('django_messages.urls', namespace='messages_inbox'),
then it is called in a template like this...
<li id="navpm">{% trans "PM" %}</li>
I think it has something to do with the two namespaces, but I haven't been able to nail it down. Any ideas?
EDIT:
The problem is that there is no line 86 in the urls.py that is in the traceback, there are only 19 lines...
there is a line 86 in another urls.py that is being used in this instance, but there are no errors there as far as I can see, and I have never touched it...
here is lines 85-91 of that urls.py...
# LOFI Extension
if (forum_settings.LOFI_SUPPORT):
urlpatterns += patterns('',
url('^lofi/$', forum_views.index, {'full':False}, name='lofi_index'),
url('^(?P<forum_id>\d+)/lofi/$', forum_views.show_forum, {'full':False}, name='lofi_forum'),
url('^topic/(?P<topic_id>\d+)/lofi/$', forum_views.show_topic, {'full':False}, name='lofi_topic'),
)
You have missed a closing parenthesis on this line
url(r'^messages/', include('django_messages.urls', namespace='messages_inbox'),
You have closed the include() call, but you need a second ) to close the url(). It should be:
url(r'^messages/', include('django_messages.urls', namespace='messages_inbox')),

Categories

Resources