Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I recently had this issue with my web application in Django :

SyntaxError at /
invalid syntax (views.py, line 98)
Request Method: GET
Request URL:    http://craft.irisa.fr/
Django Version: 1.6.5
Exception Type: SyntaxError
Exception Value:    
invalid syntax (views.py, line 98)
Exception Location: /usr/lib/python3.2/importlib/_bootstrap.py in get_code, line 413
Python Executable:  /root/CRAFT/trunk/sources/env/bin/python
Python Version: 3.2.3

a part of the code of my views.py file :

def login_view(request):
""" Logs a user into the application """

# Redirect if user is already connected
if request.user.is_authenticated():
    return HttpResponseRedirect('/')

if request.method == 'POST':
    # Get the values from the sent form
    login_form = AuthenticationForm(data=request.POST)

    # Log the user in if the form is valid
    if login_form.is_valid():
        login(request, login_form.get_user())

#line 98 is here : 
        messages.add_message(request, messages.INFO, u'Welcome back '+ request.user.username +'!')

        next = request.POST.get('next','/')
        return HttpResponseRedirect(next)
else:
    next = request.GET.get('next','/')
    # Create the form
    login_form = AuthenticationForm()

# Display the page
return render(request, 'taskHandler/login.html', locals())

As you can see there is no syntax error in this line and my code works, I tested it.

But the new thing I did is : I have changed django sgbd from sqlite3 to postgresql.

Those troubles appeared when I did these modifications so I would like to understand why python raises such an error ! I tried to add data in my database with manage.py shell and I had no problem to do so !

Thanks for your help !

Erwann

Edit : the full error trace back

Environment:

Request Method: GET
Request URL: http://craft.irisa.fr/

Django Version: 1.6.5
Python Version: 3.2.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'taskHandler',
 'widget_tweaks',
 'south')
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 "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/handlers/base.py" in get_response
  99.                 resolver_match = resolver.resolve(request.path_info)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/urlresolvers.py" in resolve
  339.                     sub_match = pattern.resolve(new_path)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/urlresolvers.py" in resolve
  339.                     sub_match = pattern.resolve(new_path)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/urlresolvers.py" in resolve
  223.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/urlresolvers.py" in callback
  230.         self._callback = get_callable(self._callback_str)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/utils/functional.py" in wrapper
  32.         result = func(*args)
File "/root/CRAFT/trunk/sources/env/lib/python3.2/site-packages/django/core/urlresolvers.py" in get_callable
  97.             mod = import_module(mod_name)
File "/usr/lib/python3.2/importlib/__init__.py" in import_module
  124.     return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/lib/python3.2/importlib/_bootstrap.py" in _gcd_import
  821.                     loader.load_module(name)
File "/usr/lib/python3.2/importlib/_bootstrap.py" in load_module
  436.         return self._load_module(fullname)
File "/usr/lib/python3.2/importlib/_bootstrap.py" in decorated
  141.             return fxn(self, module, *args, **kwargs)
File "/usr/lib/python3.2/importlib/_bootstrap.py" in _load_module
  330.         code_object = self.get_code(name)
File "/usr/lib/python3.2/importlib/_bootstrap.py" in get_code
  413.                                 dont_inherit=True)

Exception Type: SyntaxError at /
Exception Value: invalid syntax (views.py, line 98)
share|improve this question
    
Please show the full error traceback. –  Daniel Roseman Jun 27 at 9:21
    
I edited my post :) –  Legwann Jun 27 at 9:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.