Forums

Error NameError: name 'os' is not defined

Hello, I al installing a site Django but I have a problem. I modified my file /xxx_pythonanywhere_com_wsgi.py because I forgot 'import os'. I saved, I reloaded site but it's always the old file wich is read. Thank's for your help

Are you sure that you're importing it before you're using it? Are you sure that the code you're changing is the code that you're running in your web app? Are you sure the error is coming from the file where you added the import and not another one?

I thaught that the file file /xxx_pythonanywhere_com_wsgi.py which is executed was the file that I can modify in the interface in the section WEB/Code. Before modification, line number of the line where I wrote "os.environ['DJANGO_SETTINGS_MODULE'] = 'vocalibre.settings'" was 85, now it's 51, but the message is still : "File "/var/www/xxx_pythonanywhere_com_wsgi.py", line 85, in <module> 2018-05-21 14:43:38,358: os.environ['DJANGO_SETTINGS_MODULE'] = 'vocalibre.settings'" I verified, os is installed

Did you reload your web app after making the change?

yes,I saved th file and after I reload with the button of the interface

Are you sure you're not just reading the same error message? Is the time in the log changing every time you reload and check?

You are right, I am stupid ! Now I have an error but it's not the same. Thank's for your help

Glad we could help :-)

name 'os' is not defined

If you're getting that error message, you probably just need to add import os to your code.