1

带有注释的行超过 80 个字符:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    'whitelabels.middleware.SetWhitelabelMiddleware', # after SetLanguageMiddleware
    'myaffiliateprogram.middleware.BlockReferringURLs',
)

我可以打破它的最自然的方法是:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    'whitelabels.middleware.'
        'SetWhitelabelMiddleware', # after SetLanguageMiddleware
    'myaffiliateprogram.middleware.BlockReferringURLs',
)

不幸的是,悬挂缩进违反了 PEP8。

提前感谢您向我展示您将如何打破这条线。

4

1 回答 1

9

我只想移动评论:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    # This middleware needs to be after SetLanguageMiddleware
    'whitelabels.middleware.SetWhitelabelMiddleware',
    'myaffiliateprogram.middleware.BlockReferringURLs',
)
于 2013-05-06T21:46:31.507 回答