我注意到每当我使用重定向语句时,都会出现错误
unindent does not match any outer indentation level (views.py, line 16)
我不确定我在这里做错了什么。只要我删除重定向代码并放置 render_to_response 我就能看到响应。我究竟做错了什么?
/Library/Python/2.7/site-packages/Django-1.4.2-py2.7.egg/django/core/handlers/base.py in get_response
response = callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/priyank/dev/projects/asome/asom/usr/views.py in dashboard
def dashboard(request):
if not request.user.is_authenticated():
return redirect('/login/?next=%s' % request.path)
else:
user = request.user
user_orders = Order.objects.filter(user=user.user_id)
return render_to_response('views/usr/dashboard.html',{'my_orders':user_orders})
在此站点上查看类似问题后,我也尝试了此命令。
python -m tabnanny views.py
但它没有给出任何错误。
这是我的文件。
from django.shortcuts import render_to_response,redirect
from django.contrib.auth import logout
import helper as uhelper
from django.contrib.auth.models import User
from business.models import BusinessUser
from utils.core_classes import UserContext
import utils.constants as constants
from order.models import Order
def signup(request):
if request.method == 'GET':
return render_to_response('views/usr/register.html')
elif request.method == 'POST':
params = request.POST
user = User.objects.create_user(params['email'], params['email'], params['password'])
user.save()
return authenticate(request)
def login(request):
return render_to_response('views/usr/login.html')
def logout_user(request):
logout(request)
return redirect('/');
def dashboard(request):
if not request.user.is_authenticated():
return redirect('/login/?next=%s' % request.path)
else:
user = request.user
user_orders = Order.objects.filter(user=user.user_id)
return render_to_response('views/usr/dashboard.html',{'my_orders':user_orders})
def profile(request):
user = request.user
if request.method == 'GET':
return render_to_response('views/usr/profile.html')
elif request.method == 'POST':
return render_to_response('views/usr/profile.html')
def authenticate(request):
user_dict = request.POST
user = User()
user = uhelper.authenticate_user(user_dict['email'], user_dict['password'])
if user != None:
return redirect('/usr/dashboard')
这是一个回溯
/Library/Python/2.7/site-packages/Django-1.4.2-py2.7.egg/django/core/handlers/base.py in get_response
response = callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/priyank/dev/projects/stuffednow/stuffed/usr/views.py in dashboard
return redirect('/login/?next=%s' % request.path) ...
▶ Local vars
/Library/Python/2.7/site-packages/Django-1.4.2-py2.7.egg/django/shortcuts/__init__.py in redirect
return redirect_class(urlresolvers.reverse(to, args=args, kwargs=kwargs))