gpt4 book ai didi

python - Vim 没有正确缩进 Python——Flask 应用程序、Trisquel Mini GNU/Linux、lxterminal

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:10 26 4
gpt4 key购买 nike

我正在浏览 Miguel Ginberg's Flask Mega-Tutorial .我正在处理的缩进不正确的文件是 microblog/app/views.py,它看起来像这样:

from flask import render_template, flash, redirect, session, url_for, request, g
from flask_login import login_user, logout_user, current_user, login_required
from app import app, db, lm, oid
from .forms import LoginForm
from .models import User

@app.route('/')
@app.route('/index')
def index():
user = {'nickname': 'Phaed'}
posts = [
{
'author': {'nickname': 'John'},
'body': 'Beautiful day in Portland!'
},
{
'author': {'nickname': 'Susan'},
'body': 'The Avengers movie was so cool!'
}
]
return render_template('index.html',
title='Home',
user=user,
posts=posts)

@app.route('/login', methods=['GET', 'POST'])
@oid.loginhandler
def login():
if g.user is not None and g.user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
session['remember_me'] = form.remember_me.data
return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
return render_template('login.html',
title='Sign In',
form=form,
providers=app.config['OPENID_PROVIDERS'])

@lm.user_loader
def load_user(id):
return User.query.get(int(id))

当我在这个文件上执行 gg=G 时,我的缩进被弄乱了。我的示例数据初始化语句、render_template 参数、@app.route('/login', ...) 和@lm.user_loader 的方括号和大括号;他们都搞砸了:

from flask import render_template, flash, redirect, session, url_for, request, g
from flask_login import login_user, logout_user, current_user, login_required
from app import app, db, lm, oid
from .forms import LoginForm
from .models import User

@app.route('/')
@app.route('/index')
def index():
user = {'nickname': 'Phaed'}
posts = [
{
'author': {'nickname': 'John'},
'body': 'Beautiful day in Portland!'
},
{
'author': {'nickname': 'Susan'},
'body': 'The Avengers movie was so cool!'
}
]
return render_template('index.html',
title='Home',
user=user,
posts=posts)

@app.route('/login', methods=['GET', 'POST'])
@oid.loginhandler
def login():
if g.user is not None and g.user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
session['remember_me'] = form.remember_me.data
return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
return render_template('login.html',
title='Sign In',
form=form,
providers=app.config['OPENID_PROVIDERS'])

@lm.user_loader
def load_user(id):
return User.query.get(int(id))

这是为什么?我认为它一定是 .vimrc 设置,但经过数小时的阅读和调整但没有运气,我在这里发布。我的 .vimrc 中的缩进规则:

set autoindent
set smartindent
filetype plugin indent on
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4

非常感谢任何帮助。谢谢!

最佳答案

没关系!仍然很好奇如何在不使用包管理器的情况下解决这个问题,但我开始使用 Vundle 来试用这个 PEP8 缩进包,然后 -voila-。

https://github.com/Vimjas/vim-python-pep8-indent

干杯!

关于python - Vim 没有正确缩进 Python——Flask 应用程序、Trisquel Mini GNU/Linux、lxterminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42445668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com