0
我注意到,每當我用重定向語句,我得到一個錯誤Django的取消縮進不匹配任何外部縮進級別
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))
也許你的縮進中混合了製表符和空格符?另外,你的'views.py'中的第16行是什麼? – BrenBarn
我不認爲我有。爲了快速測試,我創建了另一個def並添加了重定向塊。每當我補充說我開始出現以上錯誤。 – priyank
發佈前20行。 –