Forums

NameError: name 'Path' is not defined

I'm following the djangogirls tutorial and everytime my app attempts to collect static I end up with these errors, so I can't --nuke the server or create a superuser. The real problem with this error is that my settings.py stops at line 122, so fixing the path variable at 124 isn't even an option here. I've checked both my github and my local app and they both stop at line 122.

 Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 308, in execute
    settings.INSTALLED_APPS
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/dixoncodes/dixoncodes.pythonanywhere.com/mysite/settings.py", line 124, in <module>
    MEDIA_ROOT = Path(BASE_DIR / 'media')
NameError: name 'Path' is not defined

These are the last few lines of my settings.py file.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Looks like you run your manage.py with python2.7. Run it with the python that your web app is using. Could you tell us step by step what you did? It looks like you do not use our deployment script that is recommended in the Django tutorial.

I ended up starting over and got it to work.

Great, glad to hear it's working now.

У меня такая же ошибка, у меня версия python 3.8.9, локально сервер работает. Хочу закинуть нна сервер и создать блог выходит тоже самое. скажите пожал уйста в чем проблема

@Abdulkadirov94 Is it Django? In the case of Django, you should follow https://help.pythonanywhere.com/pages/DeployExistingDjangoProject/ and user correct python version.