我有以下代码在我的1.5版Django
上运行得很好def login(request):
c={}
#c.update(csrf(request))
loginform = LoginForm()
c['loginform'] = loginform
if request.method=='POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth_login(request, user)
if user.is_staff:
return redirect('dashboard')
else:
return redirect('fullcalendar')
else:
msg = "Your account has been disabled!"
c['msg'] = msg
return render_to_response('login_disabled.html', c, context_instance=RequestContext(request))
else:
msg = "Your username and password were incorrect. Please try again."
c['msg'] = msg
return render_to_response('login_incorrect.html', c, context_instance=RequestContext(request))
return render_to_response('login.html', c, context_instance=RequestContext(request))
但升级到Django 1.6后,我收到以下错误
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/avlahop/development/django/rhombus2/rhombus/accounts/views.py" in login
45. return render_to_response('login.html', c, context_instance=RequestContext(request))
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
169. return t.render(context_instance)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
140. return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
840. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
78. return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
123. return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
840. bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
78. return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
433. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
509. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _reverse_with_prefix
387. possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
296. self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
273. for name in pattern.reverse_dict:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
296. self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
285. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in callback
229. self._callback = get_callable(self._callback_str)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in wrapper
32. result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in get_callable
96. mod = import_module(mod_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
Exception Type: SyntaxError at /accounts/login/
Exception Value: invalid syntax (views.py, line 3) #which views is that.
所有进口
from django.shortcuts import redirect, render_to_response
from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
from django.core.context_processors import csrf
#from django.core.urlresolvers import reverse
from accounts.forms import LoginForm
from django.template.context import RequestContext
它还会在此行中产生另一个错误
<a class="navbar-brand" href="{% url 'mycal.views.fullcalendar' %}">Company</a>
我有一个名为fullcalendar的网址和视图。
它在Django 1.5中运行良好。改变了什么?