1👍
This looks to me like a difference in how new lines are encoded. Indeed, Windows uses a carriage return (\r
) [wiki] and then a line feed (\n
) [wiki], whereas Linux and Mac OS X use a line feed (\n
) only. Now often certain systems will then also interpret this as a new line. But this is rendering, not the content. Likely the editor in which you look at the file has set the line endings on \n
or LF or Linux.
You can however clean the input before saving it with:
def index(request):
if 'title' in request.POST and 'content' in request.POST:
save_data(
request.POST['title'], request.POST['content'].replace('\r\n', '\n')
)
return render(request, "my_app/page.html")
Note: Please use
request.POST['content']
overrequest.POST.get('content')
. Using.get(…)
often only silences the error, but not the problem: indeed it will work if the key is missing. But if the value for that key is really required, it will only result in more trouble later in the process.