“unexpected indent” error when using notepad++ for creating django function

帅比萌擦擦* 提交于 2020-01-01 04:18:27

问题


I am following this book to learn django using notepad++, something interesting happens, when I type the function using notepad++ for the following script:

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

It gives me an error like this:

IndentationError at /time/

('unexpected indent', ('M:\\DjangoStack\\projects\\beta_01\\..\\beta_01\\hello_world\\views.py', 12, 1, '\thtml = "<html>"\n'))

But when I paste it directly from the book, it is OK. I wonder why, should I do some settings in notepad++? Thanks.

update 01

I use 4 space bars to create the indent in notepad++, I tried 1 tab and seems the problem is fixed


回答1:


Tell Notepad++ to show you all characters: go View > Show Symbol > Show All Characters. This will show tabs as and spaces as . Replace tabs with spaces where necessary to normalize the indentation.




回答2:


Settings->Preferences->Language Menu/Tab Settings->"Replace by space"




回答3:


In Notepad++ it is a checkbox here:

  • Settings>Preferences>



来源:https://stackoverflow.com/questions/8483969/unexpected-indent-error-when-using-notepad-for-creating-django-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!