Django: TypeError: 'str' object is not callable, referer: http://xxx

Posted by user705415 on Stack Overflow See other posts from Stack Overflow or by user705415
Published on 2012-04-10T15:57:38Z Indexed on 2012/04/10 17:29 UTC
Read the original article Hit count: 340

I've been wondering why when I set the settings.py of my django project 'arvindemo' debug = Flase and deploy it on Apache with mod_wsgi, I got the 500 Internal Server Error.

Env: Django 1.4.0 Python 2.7.2 mod_wsgi 2.8 OS centOS

Here is the recap: Visit the homepage, go to sub page A/B/C/D, and fill some forms, then submit it to the Apache server. Once click 'submit' button, I will get the '500 Internal Server Error', and the error_log listed below(Traceback):

[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250] Traceback (most recent call last):
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     response = self.get_response(request)
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/python2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     if resolver.urlconf_module is None:
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/python2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     self._urlconf_module = import_module(self.urlconf_name)
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/python2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     __import__(name)
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]   File "/opt/web/django/arvindemo/arvindemo/../arvindemo/urls.py", line 23, in <module>
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250]     url(r'^submitPage$', name=submitPage),
[Tue Apr 10 10:07:20 2012] [error] [client 122.198.133.250] TypeError: url() takes at least 2 arguments (2 given)

When using django runserver, I set arvindemo.settings debug = True, everything is OK. But things changed once I set debug = Flase.

Here is my views.py

from django.http import HttpResponseRedirect
from django.http import HttpResponse, HttpResponseServerError
from django.shortcuts import render_to_response
import datetime, string
from user_info.models import *
from django.template import Context, loader, RequestContext
import settings
def hello(request):
    return HttpResponse("hello girl")

def helpPage(request):
    return render_to_response('kktHelp.html')

def server_error(request, template_name='500.html'):
    return render_to_response(template_name,
            context_instance = RequestContext(request)
    )

def page404(request):
    return render_to_response('404.html')

def submitPage(request):
    post = request.POST
    Mall = 'goodsName'
    Contest = 'ojs'
    Presentation = 'addr'
    WeatherReport = 'city'
    Habit = 'task'
    if Mall in post:
            return submitMall(request)
    elif Contest in post:
            return submitContest(request)
    elif Presentation in post:
            return submitPresentation(request)
    elif Habit in post:
            return submitHabit(request)
    elif WeatherReport in post:
            return submitWeather(request)
    else:
            return HttpResponse(request.POST)
            return HttpResponseRedirect('404')
def submitXXX():
  .....
def xxxx():
....

Here comes the urls.py

from django.conf.urls import patterns, include, url
from views import *
from django.conf import settings

handler500 = 'server_error'
urlpatterns = patterns('',
    url(r'^hello/$', hello),  # hello world
    url(r'^$', homePage),
    url(r'^time/$', getTime),
    url(r'^time/plus/(\d{1,2})/$', hoursAhead),
    url(r'^Ttime/$', templateGetTime),
    url(r'^Mall$', templateMall),
    url(r'^Contest$', templateContest),
    url(r'^Presentation$', templatePresentation),
url(r'^Habit$', templateHabit),
url(r'^Weather$', templateWeather),
url(r'^Help$', helpPage),
url(r'^404$', page404),
url(r'^500$', server_error),
url(r'^submitPage$', submitPage),
url(r'^submitMall$', submitMall),
url(r'^submitContest$', submitContest),
url(r'^submitPresentation$', submitPresentation),
url(r'^submitHabit$', submitHabit),
url(r'^submitWeather$', submitWeather),
url(r'^terms$', terms),
url(r'^privacy$', privacy),
url(r'^thanks$', thanks),
url(r'^about$', about),
url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATICFILES_DIRS}),
)

I'm sure there is no syntax error in my django project,cause when I use django runserver, everything is fine.

Anyone can help ?

Best regards

© Stack Overflow or respective owner

Related posts about django

Related posts about apache