Domanda

Nuovo per Python e Django. Voglio capire il codice del modulo Django-Registration per questo, voglio debug del valore nel codice. Quindi sono bloccato qui quello

i = path.rfind('.')
    module, attr = path[:i], path[i+1:]

print {i}
#or
import pdb; pdb.set_trace()

Il mio modulo di registrazione non è mostrato e dà errore.

IndentationError at /accounts/register/
unexpected indent (__init__.py, line 19)
Request Method: GET
Request URL:    http://50.56.78.125:8000/accounts/register/
Django Version: 1.3.1
Exception Type: IndentationError
Exception Value:    
unexpected indent (__init__.py, line 19)

Come posso eseguire il debug o vedere il valore di i.

Questo è il codice:

i = path.rfind('.')
    module, attr = path[:i], path[i+1:]
    try:
        mod = import_module(module)
    except ImportError, e:
        raise ImproperlyConfigured('Error loading registration backend %s: "%s"' % (module, e))
    try:
        backend_class = getattr(mod, attr)
    except AttributeError:
        raise ImproperlyConfigured('Module "%s" does not define a registration backend named "%s"' % (module, attr))
    return backend_class()
È stato utile?

Soluzione

Le rientranze contano molto in Python e, come suggerisce l'errore, hai un problema di rientranza. Dovresti solo rientrare durante la creazione di un nuovo blocco di codice, ad esempio dopo if, for o while dichiarazioni.

Basta rimuovere gli spazi bianchi prima module:

i = path.rfind('.')
module, attr = path[:i], path[i+1:]

print i
#or
import pdb; pdb.set_trace()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top