【发布时间】:2011-06-01 00:56:30
【问题描述】:
我正在使用嵌套的 if 块来决定适当的视图。但是在 if 块之后我收到了 Unexpected Indent 错误。我无法找出我在缩进中犯错的地方。
def logged_home(request):
names = request.user.social_auth.values_list('provider', flat=True)
ctx = dict((name.lower().replace('-', '_'), True) for name in names)
ctx['version'] = version
return render_to_response('logged_home.html', ctx, RequestContext(request))
def home(request):
if request.user.is_authenticated():
profile = user.get_profile()
if profile.is_new == True:
return welcome(request)
else:
return logged_home(request)
else:
return not_logged_home(request)
def signup(request):
return render_to_response('signup.html', {}, context_instance = RequestContext(request))
【问题讨论】:
-
您确定缩进错误不在 not_logged_home 或 logged_home 方法/视图中吗?
-
是的,我确定 not_logged_home 或 logged_home 中没有错误,因为在我编辑主视图之前它们执行时没有出现错误。
-
我建议在
vim中使用:set list或在其他文本编辑器中使用类似的命令来向您展示制表符和空格之间的区别。您的 IDE 可能配置为始终使用制表符,但很容易错误配置空格/制表符。 -
你为什么使用混合的 4 和 8 缩进?
-
@tmg 我想我把 vim 和 gedit 弄错了。
标签: python django django-views