Search code examples
pythondjangoprogramming-languagesstring-concatenationline-breaks

how to break lines when I concatenate strings in django


hy guys, I needed again of the help of you. Now i want to make a break line when i concatenate strings, i tried to do of this way:

    r['placa_desc'] = PessoaFrota(request,dbcur).get_placa_choices(r.get('placa'))
    if r.get('placa_desc'):
        r['placa'] =   \n + r.get('placa_desc')[0]

but when i try to make this, i got this error:

Exception Value:
unexpected character after line continuation character (views.py, line 250)

Can somebody help me?


Solution

  • You need to quote your \n:

    r['placa'] =   \n + r.get('placa_desc')[0]
    
    r['placa'] =   "\n" + r.get('placa_desc')[0]
    

    or python thinks the \ is a continuation character. Try that.